#include<bits/stdc++.h>
#include<math.h>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<vector>
#include<string>
#define MAXN 100001
#define Endl '\n'
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define up  upper_bound
#define ll long long int
#define pii pair<ll,ll>
#define all(v) v.begin(),v.end()
#define fi(x,n) for(ll i=x;i<n;i++)
#define fj(x,n) for(ll j=x;j<n;j++)
#define fk(x,n) for(ll k=x;k<n;k++)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll exp(ll x,ll y,ll mod)
{
	ll res=1;
	x=x%mod;
	while(y>0)
	{
		if(y&1)
			res=(res*x)%mod;
		y = y>>1;
		x=(x*x)%mod;
	}
	return res;
}
ll modinverse(ll x,ll mod)
{
    return exp(x,mod-2,mod);
}
using namespace std;
const ll inf = 0x3f3f3f3f3f3f3f3fll;
ll dp[26][26];
int main()
{
    fastio;
    ll n,d;
    cin>>n;
    vector <ll> ans;
    string s;
    cin>>s;

    ll x,y,res=0;
    fi(0,n)
    {
        x=s[i]-'0';
        res=0;
        fj(i+1,n)
        {
            if((s[j]-'0')>=x)
                y=(s[j]-'0')-x;
            else
                y=10-(x-(s[j]-'0'));

            res=res*10+y;
        }

        fj(0,i)
        {
            if((s[j]-'0')>=x)
                y=(s[j]-'0')-x;
            else
                y=10-(x-(s[j]-'0'));

            res=res*10+y;
        }
        ans.pb(res);
    }
    res=*min_element(all(ans));

    if(res!=0)
        d=(ll)log10(res)+1;
    else
        d=1;

    fi(0,n-d)
        cout<<0;
    cout<<res;

    return 0;
}


#include<bits/stdc++.h>
#include<math.h>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<vector>
#include<string>
#define MAXN 100001
#define Endl '\n'
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define up  upper_bound
#define ll long long int
#define pii pair<ll,ll>
#define all(v) v.begin(),v.end()
#define fi(x,n) for(ll i=x;i<n;i++)
#define fj(x,n) for(ll j=x;j<n;j++)
#define fk(x,n) for(ll k=x;k<n;k++)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll exp(ll x,ll y,ll mod)
{
	ll res=1;
	x=x%mod;
	while(y>0)
	{
		if(y&1)
			res=(res*x)%mod;
		y = y>>1;
		x=(x*x)%mod;
	}
	return res;
}
ll modinverse(ll x,ll mod)
{
    return exp(x,mod-2,mod);
}
using namespace std;
const ll inf = 0x3f3f3f3f3f3f3f3fll;
ll dp[26][26];
int main()
{
    fastio;
    ll n,d;
    cin>>n;
    set <string> ans;
    string s;
    cin>>s;

    char y;
    fi(0,n)
    {
        string res="";
        fj(i,n)
        {
            if(s[j]>=s[i])
                y=(s[j]-s[i])+'0';
            else
                y=(9+'0')-(s[i]-s[j]);
            res+=y;
        }

        fj(0,i)
        {
            if(s[j]>=s[i])
                y=(s[j]-s[i])+'0';
            else
                y=(9+'0')-(s[i]-s[j]);
            res+=y;
        }
        ans.insert(res);
    }
    cout<<*(ans.begin());

    return 0;
}


#include<bits/stdc++.h>
#include<math.h>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<vector>
#include<string>
#define MAXN 100001
#define Endl '\n'
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define up  upper_bound
#define ll long long int
#define pii pair<ll,ll>
#define all(v) v.begin(),v.end()
#define fi(x,n) for(ll i=x;i<n;i++)
#define fj(x,n) for(ll j=x;j<n;j++)
#define fk(x,n) for(ll k=x;k<n;k++)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll exp(ll x,ll y,ll mod)
{
	ll res=1;
	x=x%mod;
	while(y>0)
	{
		if(y&1)
			res=(res*x)%mod;
		y = y>>1;
		x=(x*x)%mod;
	}
	return res;
}
ll modinverse(ll x,ll mod)
{
    return exp(x,mod-2,mod);
}
using namespace std;
const ll inf = 0x3f3f3f3f3f3f3f3fll;
ll dp[26][26];
int main()
{
    fastio;
    ll n,d;
    cin>>n;
    set <string> ans;
    string s;
    cin>>s;

    char y;
    fi(0,n)
    {
        string res="";
        fj(i,n)
        {
            if(s[j]>=s[i])
                y=(s[j]-s[i])+'0';
            else
                y=(10+'0')-(s[i]-s[j]);
            res+=y;
        }

        fj(0,i)
        {
            if(s[j]>=s[i])
                y=(s[j]-s[i])+'0';
            else
                y=(10+'0')-(s[i]-s[j]);
            res+=y;
        }
        ans.insert(res);
    }
    cout<<*(ans.begin());

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    string a;
    int n;
    cin>>n;
    int k,arr[10]={0},dup[10]={0},index,steps,cnt=0;
    cin>>a;
    for(int i=0;i<a.size();i++)
    {
        k=a.at(i);
        arr[k-48]++;
        dup[k-48]++;
    }
    sort(arr,arr+10);
    if(arr[9]==1)
    {
        for(int i=0;i<10;i++)
        {
            if(dup[i]!=0)
            {
                index=i;
                break;
            }
        }
        steps=10-index;
        for(int i=0;i<a.size();i++)
        {
            k=a.at(i);
            if(k+steps>=58)
            {
                a.at(i)+=(steps-10);
            }else
            {
                a.at(i)+=(steps);
            }
        }
    }else
    {
        for(int i=0;i<10;i++)
        {
            if(arr[9]==dup[i])
            {
                index=i;
                break;
            }
        }
        steps=10-index;
        cout<<index<<endl;
        for(int i=0;i<a.size();i++)
        {
            k=a.at(i);
            if(k+steps>=58)
            {
                a.at(i)+=(steps-10);
            }else
            {
                a.at(i)+=(steps);
            }
        }
    }
    deque <int> dq;
    for(int i=0;i<a.size();i++)
    {
        dq.push_back(a.at(i)-48);
    }
    int no_of_zeroes=arr[9];
    while(true)
    {
        for(int i=0;i<no_of_zeroes;i++)
        {
            if(dq.front()==0)
            {
                cnt++;
            }
        }
        if(no_of_zeroes==cnt)
        {
            break;
        }
        cnt=0;
        dq.push_front(dq.back());
        dq.pop_back();
    }
    deque<int> :: iterator it=dq.begin();
    for(int i=0;i<dq.size();i++)
    {
        cout<<*it;
        it++;
    }
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    string a,b;
    int n,k,arr[10]={0},dup[10]={0},index,steps,cnt=0,largest;
    cin>>n;
    cin>>a;
    b=a;
    for(int i=0;i<n;i++)
    {
        k=a.at(i);
        arr[k-48]++;
        dup[k-48]++;
    }
    for(int i=9;i>=0;i--)
    {
        if(arr[i]!=0)
        {
            largest = i;
            break;
        }
    }
    sort(arr,arr+10);
    if(arr[9]==1)
    {
        for(int i=1;i<10;i++)
        {
            if(dup[i]!=0)
            {
                index=i;
                break;
            }
        }
        steps=10-index;
        for(int i=0;i<n;i++)
        {
            k=a.at(i);
            if(k+steps>=58)
            {
                a.at(i)+=(steps-10);
            }else
            {
                a.at(i)+=(steps);
            }
        }
        deque <int> dq1;
        for(int i=0;i<n;i++)
        {
            dq1.push_back(a.at(i)-48);
        }
        while(true)
        {
            if(dq1.front()==0)
            {
                break;
            }
            dq1.push_front(dq1.back());
            dq1.pop_back();
        }
        deque<int> :: iterator it1=dq1.begin();
        steps=10-largest;
        for(int i=0;i<n;i++)
        {
            k=b.at(i);
            if(k+steps>=58)
            {
                b.at(i)+=(steps-10);
            }else
            {
                b.at(i)+=(steps);
            }
        }
        deque <int> dq2;
        for(int i=0;i<n;i++)
        {
            dq2.push_back(b.at(i)-48);
        }
        while(true)
        {
            if(dq2.front()==0)
            {
                break;
            }
            dq2.push_front(dq2.back());
            dq2.pop_back();
        }
        deque<int> :: iterator it2=dq2.begin();
        for(int i=0;i<n;i++)
        {
            if(*it1<*it2)
            {
                deque<int> :: iterator it=dq1.begin();
                for(int i=0;i<n;i++)
                {
                    cout<<*it;
                    it++;
                }
                return 0;
            }else if(*it1>*it2)
            {
                deque<int> :: iterator it=dq2.begin();
                for(int i=0;i<n;i++)
                {
                    cout<<*it;
                    it++;
                }
                return 0;
            }
            it1++;
            it2++;
        }
    }else
    {
        for(int i=0;i<10;i++)
        {
            if(arr[9]==dup[i])
            {
                index=i;
                break;
            }
        }
        steps=10-index;
        for(int i=0;i<n;i++)
        {
            k=a.at(i);
            if(k+steps>=58)
            {
                a.at(i)+=(steps-10);
            }else
            {
                a.at(i)+=(steps);
            }
        }
    }
    deque <int> dq;
    for(int i=0;i<n;i++)
    {
        dq.push_back(a.at(i)-48);
    }
    int no_of_zeroes=arr[0];
    while(true)
    {
        for(int i=0;i<no_of_zeroes;i++)
        {
            if(dq.front()==0)
            {
                cnt++;
            }
        }
        if(no_of_zeroes==cnt)
        {
            break;
        }
        cnt=0;
        dq.push_front(dq.back());
        dq.pop_back();
    }
    deque<int> :: iterator it=dq.begin();
    for(int i=0;i<n;i++)
    {
        cout<<*it;
        it++;
    }
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    string a;
    int k,arr[10]={0},dup[10]={0},index,steps,cnt=0;
    cin>>a;
    for(int i=0;i<a.size();i++)
    {
        k=a.at(i);
        arr[k-48]++;
        dup[k-48]++;
    }
    sort(arr,arr+10);
    if(arr[9]==1)
    {
        for(int i=0;i<10;i++)
        {
            if(dup[i]!=0)
            {
                index=i;
                break;
            }
        }
        steps=10-index;
        for(int i=0;i<a.size();i++)
        {
            k=a.at(i);
            if(k+steps>=58)
            {
                a.at(i)+=(steps-10);
            }else
            {
                a.at(i)+=(steps);
            }
        }
    }else
    {
        for(int i=0;i<10;i++)
        {
            if(arr[9]==dup[i])
            {
                index=i;
                break;
            }
        }
        steps=10-index;
        cout<<index<<endl;
        for(int i=0;i<a.size();i++)
        {
            k=a.at(i);
            if(k+steps>=58)
            {
                a.at(i)+=(steps-10);
            }else
            {
                a.at(i)+=(steps);
            }
        }
    }
    deque <int> dq;
    for(int i=0;i<a.size();i++)
    {
        dq.push_back(a.at(i)-48);
    }
    int no_of_zeroes=arr[9];
    while(true)
    {
        for(int i=0;i<no_of_zeroes;i++)
        {
            if(dq.front()==0)
            {
                cnt++;
            }
        }
        if(no_of_zeroes==cnt)
        {
            break;
        }
        cnt=0;
        dq.push_front(dq.back());
        dq.pop_back();
    }
    deque<int> :: iterator it=dq.begin();
    for(int i=0;i<dq.size();i++)
    {
        cout<<*it;
        it++;
    }
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    string a;
    int n,k,arr[10]={0},dup[10]={0},index,steps,cnt=0,largest;
    cin>>n;
    cin>>a;
    for(int i=0;i<a.size();i++)
    {
        k=a.at(i);
        arr[k-48]++;
        dup[k-48]++;
    }
    for(int i=9;i>=0;i--)
    {
        if(arr[i]!=0)
        {
            largest = i;
            break;
        }
    }
    sort(arr,arr+10);
    if(arr[9]==1)
    {
        if(largest<=5)
        {
            for(int i=1;i<10;i++)
            {
                if(dup[i]!=0)
                {
                    index=i;
                    break;
                }
            }
            steps=10-index;
            for(int i=0;i<a.size();i++)
            {
                k=a.at(i);
                if(k+steps>=58)
                {
                    a.at(i)+=(steps-10);
                }else
                {
                    a.at(i)+=(steps);
                }
            }
        }else
        {
            steps=10-largest;
            for(int i=0;i<a.size();i++)
            {
                k=a.at(i);
                if(k+steps>=58)
                {
                    a.at(i)+=(steps-10);
                }else
                {
                    a.at(i)+=(steps);
                }
            }
        }
    }else
    {
        for(int i=0;i<10;i++)
        {
            if(arr[9]==dup[i])
            {
                index=i;
                break;
            }
        }
        steps=10-index;
        for(int i=0;i<a.size();i++)
        {
            k=a.at(i);
            if(k+steps>=58)
            {
                a.at(i)+=(steps-10);
            }else
            {
                a.at(i)+=(steps);
            }
        }
    }
    deque <int> dq;
    for(int i=0;i<a.size();i++)
    {
        dq.push_back(a.at(i)-48);
    }
    int no_of_zeroes=arr[9];
    while(true)
    {
        for(int i=0;i<no_of_zeroes;i++)
        {
            if(dq.front()==0)
            {
                cnt++;
            }
        }
        if(no_of_zeroes==cnt)
        {
            break;
        }
        cnt=0;
        dq.push_front(dq.back());
        dq.pop_back();
    }
    deque<int> :: iterator it=dq.begin();
    for(int i=0;i<dq.size();i++)
    {
        cout<<*it;
        it++;
    }
}


#include<iostream>

using namespace std;

int main()
{
    int n;
    string s,a,b;
    cin>>n>>s;
    b=s;
    for(int j=0;j<10;j++)
    {
        for(int i=0;i<n;i++)
        {
            s[i]=(s[i]-'0'+1)%10+'0';
        }
        a=s+s;
        for(int i=0;i<n;i++)
        {
            b=min(b,a.substr(i,n));
        }
    }
    cout<<b;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    string a,b;
    int n,k,arr[10]={0},dup[10]={0},index,steps,cnt=0,largest;
    cin>>n;
    cin>>a;
    b=a;
    for(int i=0;i<n;i++)
    {
        k=a.at(i);
        arr[k-48]++;
        dup[k-48]++;
    }
    for(int i=9;i>=0;i--)
    {
        if(arr[i]!=0)
        {
            largest = i;
            break;
        }
    }
    sort(arr,arr+10);
    if(arr[9]==1)
    {
        for(int i=1;i<10;i++)
        {
            if(dup[i]!=0)
            {
                index=i;
                break;
            }
        }
        steps=10-index;
        for(int i=0;i<n;i++)
        {
            k=a.at(i);
            if(k+steps>=58)
            {
                a.at(i)+=(steps-10);
            }else
            {
                a.at(i)+=(steps);
            }
        }
        deque <int> dq1;
        for(int i=0;i<n;i++)
        {
            dq1.push_back(a.at(i)-48);
        }
        while(true)
        {
            if(dq1.front()==0)
            {
                break;
            }
            dq1.push_front(dq1.back());
            dq1.pop_back();
        }
        deque<int> :: iterator it1=dq1.begin();
        steps=10-largest;
        for(int i=0;i<n;i++)
        {
            k=b.at(i);
            if(k+steps>=58)
            {
                b.at(i)+=(steps-10);
            }else
            {
                b.at(i)+=(steps);
            }
        }
        deque <int> dq2;
        for(int i=0;i<n;i++)
        {
            dq2.push_back(b.at(i)-48);
        }
        while(true)
        {
            if(dq2.front()==0)
            {
                break;
            }
            dq2.push_front(dq2.back());
            dq2.pop_back();
        }
        deque<int> :: iterator it2=dq2.begin();
        for(int i=0;i<n;i++)
        {
            if(*it1<*it2)
            {
                deque<int> :: iterator it=dq1.begin();
                for(int i=0;i<n;i++)
                {
                    cout<<*it;
                    it++;
                }
                return 0;
            }else if(*it1>*it2)
            {
                deque<int> :: iterator it=dq2.begin();
                for(int i=0;i<n;i++)
                {
                    cout<<*it;
                    it++;
                }
                return 0;
            }
            it1++;
            it2++;
        }
    }else
    {
        for(int i=0;i<10;i++)
        {
            if(arr[9]==dup[i])
            {
                index=i;
                break;
            }
        }
        steps=10-index;
        for(int i=0;i<n;i++)
        {
            k=a.at(i);
            if(k+steps>=58)
            {
                a.at(i)+=(steps-10);
            }else
            {
                a.at(i)+=(steps);
            }
        }
    }
    deque <int> dq;
    for(int i=0;i<n;i++)
    {
        dq.push_back(a.at(i)-48);
    }
    int no_of_zeroes=arr[9];
    while(true)
    {
        for(int i=0;i<no_of_zeroes;i++)
        {
            if(dq.front()==0)
            {
                cnt++;
            }
        }
        if(no_of_zeroes==cnt)
        {
            break;
        }
        cnt=0;
        dq.push_front(dq.back());
        dq.pop_back();
    }
    deque<int> :: iterator it=dq.begin();
    for(int i=0;i<n;i++)
    {
        cout<<*it;
        it++;
    }
}


#include<bits/stdc++.h>
using namespace std;
int n;
string s;
int main()
{

    cin>>n;
    cin>>s;
    char ans[1010];
    for(int i=0; i<1001; i++)
        ans[i]='9';

    string answer=ans;
    for(int i=1; i<=9; i++)
    {
        string a=s+s;
        for(int i=0; i<n; i++)
        {
            string b=a.substr(i,n);
            answer=min(answer,b);
        }

        for(int i=0; i<n; i++)
        {
            if(s[i]=='9')
                s[i]='0';
            else
                s[i]++;
        }

    }
    cout<<answer;
}


#include<bits/stdc++.h>
using namespace std;
int n;
string s;
int main()
{

    cin>>n;
    cin>>s;
    char ans[1010];
    for(int i=0; i<1001; i++)
        ans[i]='9';

    string answer=ans;
    for(int i=1; i<=10; i++)
    {
        string a=s+s;
        for(int i=0; i<n; i++)
        {
            string b=a.substr(i,n);
            answer=min(answer,b);
        }
        for(int i=0; i<n; i++)
        {
            if(s[i]=='9')
                s[i]='0';
            else
                s[i]++;
        }

    }
    cout<<answer;
}


#include<bits/stdc++.h>
using namespace std;
int TEST,CASE=1;
#define sf scanf
#define pf printf
#define pb push_back
#define nl printf("\n")
#define all(x) x.begin(),x.end()
#define clr(a,b) memset(a,b,sizeof(a))
typedef long long int ll;
typedef long double ld;
int n,m,a,b,c,k,x,y,z,len,total=0;
string s,temp,ans;
int main(void){
#ifdef FILE_INPUT
  freopen("input.txt","r",stdin);
#endif /// FILE_INPUT
  cin>>n;
  cin.ignore();
  getline(cin,s);
  temp=ans=s;
  for(int i=0;i<n*9;i++){
    for(int j=0;j<n;j++){
      if(s[j]=='0'){
        int k;
        for(k=0;j<n;k++,j++){
          temp[k]=s[j];
        }
        for(j=0;k<n;k++,j++){
          temp[k]=s[j];
        }
        ans=min(ans,temp);
        break;
      }
    }
    for(int j=0;j<n;j++){
      if(s[j]=='9')s[j]='0';
      else s[j]++;
    }
    ans=min(ans,s);
  }
  cout<<ans<<endl;
#ifdef FILE_INPUT
#endif /// FILE_INPUT
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int TEST,CASE=1;
#define sf scanf
#define pf printf
#define pb push_back
#define nl printf("\n")
#define all(x) x.begin(),x.end()
#define clr(a,b) memset(a,b,sizeof(a))
typedef long long int ll;
typedef long double ld;
int n,m,a,b,c,k,x,y,z,len,total=0;
string s,temp,ans;
int main(void){
#ifdef FILE_INPUT
  freopen("input.txt","r",stdin);
#endif /// FILE_INPUT
  cin>>n;
  cin>>s;
  temp=ans=s;
  for(int i=0;i<n*9;i++){
    for(int j=0;j<n;j++){
      if(s[j]=='0'){
        int k;
        for(k=0;j<n;k++,j++){
          temp[k]=s[j];
        }
        for(j=0;k<n;k++,j++){
          temp[k]=s[j];
        }
        ans=min(ans,temp);
        break;
      }
    }
    for(int j=0;j<n;j++){
      if(s[j]=='9')s[j]='0';
      else s[j]++;
    }
    ans=min(ans,s);
  }
  cout<<ans<<endl;
#ifdef FILE_INPUT
#endif /// FILE_INPUT
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int TEST,CASE=1;
#define sf scanf
#define pf printf
#define pb push_back
#define nl printf("\n")
#define all(x) x.begin(),x.end()
#define clr(a,b) memset(a,b,sizeof(a))
typedef long long int ll;
typedef long double ld;
int n,m,a,b,c,k,x,y,z,len,total=0;
string s,temp,ans;
int main(void){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#ifdef FILE_INPUT
  freopen("input.txt","r",stdin);
#endif /// FILE_INPUT
  while(cin>>n){
    cin>>s;
    temp=ans=s;
    for(int i=0;i<=n*9;i++){
      for(int j=0;j<n;j++){
        if(s[j]=='0'){
          int k;
          for(k=0;j<n;k++,j++){
            temp[k]=s[j];
          }
          for(j=0;k<n;k++,j++){
            temp[k]=s[j];
          }
          ans=min(ans,temp);
          break;
        }
      }
      for(int j=0;j<n;j++){
        if(s[j]=='9')s[j]='0';
        else s[j]++;
      }
      ans=min(ans,s);
    }
    cout<<ans<<endl;
  }
#ifdef FILE_INPUT
#endif /// FILE_INPUT
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int TEST,CASE=1;
#define sf scanf
#define pf printf
#define pb push_back
#define nl printf("\n")
#define all(x) x.begin(),x.end()
#define clr(a,b) memset(a,b,sizeof(a))
typedef long long int ll;
typedef long double ld;
int n,m,a,b,c,k,x,y,z,len,total=0;
string s,temp,ans;
int main(void){
#ifdef FILE_INPUT
  freopen("input.txt","r",stdin);
#endif /// FILE_INPUT
  cin>>n;
  cin>>s;
  temp=ans=s;
  for(int i=0;i<n;i++){
    k=0;
    for(int j=i;j<n;j++){
      temp[k++]=s[j];
    }
    for(int j=0;j<i;j++){
      temp[k++]=s[j];
    }
    ans=min(ans,temp);
    for(k=0;k<=9;k++){
      for(int j=0;j<n;j++){
        if(temp[j]=='9')temp[j]='0';
        else temp[j]++;
      }
      ans=min(ans,temp);
    }
  }
  cout<<ans<<endl;
#ifdef FILE_INPUT
#endif /// FILE_INPUT
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int TEST,CASE=1;
#define sf scanf
#define pf printf
#define pb push_back
#define nl printf("\n")
#define all(x) x.begin(),x.end()
#define clr(a,b) memset(a,b,sizeof(a))
typedef long long int ll;
typedef long double ld;
int n,m,a,b,c,k,x,y,z,len,total=0;
string s,temp,ans;
int main(void){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
#ifdef FILE_INPUT
  freopen("input.txt","r",stdin);
#endif /// FILE_INPUT
  cin>>n;
  cin>>s;
  temp=ans=s;
  for(int i=0;i<=n*9;i++){
    for(int j=0;j<n;j++){
      if(s[j]=='0'){
        int k;
        for(k=0;j<n;k++,j++){
          temp[k]=s[j];
        }
        for(j=0;k<n;k++,j++){
          temp[k]=s[j];
        }
        ans=min(ans,temp);
        break;
      }
    }
    for(int j=0;j<n;j++){
      if(s[j]=='9')s[j]='0';
      else s[j]++;
    }
    ans=min(ans,s);
  }
  cout<<ans<<endl;
#ifdef FILE_INPUT
#endif /// FILE_INPUT
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define inf             1e18
#define ps(x,y)         cout<<fixed<<setprecision(y)<<x;
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
#define endl            "\n"
#define f(i,n)          for(int i=0 ; i<n ; i++)
#define SIZE            200000
#define mod             1000000007
#define mod1            1000003

void ish_8()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int lcm(int a,int b)
{
	return a/__gcd(a,b)*b;
}

bool prime(int n)
{
	if(n<2)
		return false;
	for(int i=2 ; i<=sqrt(n) ; i++)
	{
		if(n%i == 0)
			return false;
	}
	return true;
}

/*int  power(int a, int b) {
 int rs = 1;
 while(b>0) {
  if(b & 1)
  {
    rs *= a;
    rs = rs%mod;
  }
  a = ((a%mod)*(a%mod))%mod;
  b >>= 1;
}
return rs%mod;
}*/

int power(int x, int y)
{
	if (y == 0)
		return 1;
	else if (y % 2 == 0)
		return (power(x, y/2)) * (power(x, (y) / 2));
	else
		return x * power(x, y / 2) * power(x, (y) / 2);
}

int log_a_to_base_b(int a, int b)
{
	if(b==1)
		return 0;
	return log(a) / log(b);
}

double kthRoot(double n, int k) {
	return pow(k, (1.0 / k) * (log(n) / log(k)));
}

int factorial(int n)
{
	if(n==0)
	{
		return 1;
	}
	return n*factorial(n-1);
}

bool compare(pii a,pii b)
{
	if(a.ff==b.ff)
		return a.ss<b.ss;
	else
		return a.ff<b.ff;
}

bool perfect(int n)
{
	float sr=sqrt(n);
	return ((sr-floor(sr))==0);
}

void solve()
{
	int n,res=INT_MAX;
	cin>>n;
	string s;
	cin>>s;
	if(n==1)
	{
		cout<<"0"<<endl;
		return;
	}
	vector<string> v;
	v.pb(s);
	for(int i=1 ; i<n ; i++)
	{
    string x=v[i-1];
    int l=x.size();
    string y = x.substr(0,l-1);
    string z = x[l-1]+y;
    v.pb(z);
	}
	f(i,v.size())
	{
		//cout<<v[i]<<" ";
		string x = v[i];
		f(k,11)
		{
			f(j,n)
			{
				int y = x[j]-'0';
				int z = (y+1)%10;
				x[j] = z+'0';
			}
			int ans=0;
			f(j,n)
			{
        int y = x[j]-'0';
        ans+=y*power(10,n-j-1);
			}
			res = min(res,ans);
		}
	}
	int cp=res,count=0;
	if(res==0)
	{
		f(i,n)cout<<"0";
		cout<<endl;
		return;
	}
	while(cp>0)
	{
		cp/=10;
		count++;
	}
	if(count<n)
	{
		f(i,n-count)cout<<"0";
	}
	cout<<res<<endl;
}

int32_t main()
{
	ish_8();
	//w(t)
	//{
		solve();
	//}
}


#include<bits/stdc++.h>
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define inf             1e18
#define ps(x,y)         cout<<fixed<<setprecision(y)<<x;
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
#define endl            "\n"
#define f(i,n)          for(int i=0 ; i<n ; i++)
#define SIZE            200000
#define mod             1000000007
#define mod1            1000003

void ish_8()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int lcm(int a,int b)
{
	return a/__gcd(a,b)*b;
}

bool prime(int n)
{
	if(n<2)
		return false;
	for(int i=2 ; i<=sqrt(n) ; i++)
	{
		if(n%i == 0)
			return false;
	}
	return true;
}

/*int  power(int a, int b) {
 int rs = 1;
 while(b>0) {
  if(b & 1)
  {
    rs *= a;
    rs = rs%mod;
  }
  a = ((a%mod)*(a%mod))%mod;
  b >>= 1;
}
return rs%mod;
}*/

int power(int x, int y)
{
	if (y == 0)
		return 1;
	else if (y % 2 == 0)
		return (power(x, y/2)) * (power(x, (y) / 2));
	else
		return x * power(x, y / 2) * power(x, (y) / 2);
}

int log_a_to_base_b(int a, int b)
{
	if(b==1)
		return 0;
	return log(a) / log(b);
}

double kthRoot(double n, int k) {
	return pow(k, (1.0 / k) * (log(n) / log(k)));
}

int factorial(int n)
{
	if(n==0)
	{
		return 1;
	}
	return n*factorial(n-1);
}

bool compare(pii a,pii b)
{
	if(a.ff==b.ff)
		return a.ss<b.ss;
	else
		return a.ff<b.ff;
}

bool perfect(int n)
{
	float sr=sqrt(n);
	return ((sr-floor(sr))==0);
}

string util(string s)
{
	int del = s[0]-'0';
	s[0]='0';
	for(int i=1 ; i<s.size() ; i++)
	{
		int d = s[i]-'0';
		int nd = (d-del+10)%10;
		s[i]=nd+'0';
	}
	return s;
}

void solve()
{
	int n;
	cin>>n;
	string s;
	cin>>s;
	string ans = util(s);
	f(i,n)
	{
		string t = s.substr(i) + s.substr(0,i);
		if(util(t)<ans)
		{
			ans = util(t);
		}
	}
	cout<<ans<<endl;
}

int32_t main()
{
	ish_8();
	//w(t)
	//{
		solve();
	//}
}


#include<bits/stdc++.h>
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define inf             1e18
#define ps(x,y)         cout<<fixed<<setprecision(y)<<x;
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
#define endl            "\n"
#define f(i,n)          for(int i=0 ; i<n ; i++)
#define SIZE            200000
#define mod             1000000007
#define mod1            1000003

void ish_8()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int lcm(int a,int b)
{
	return a/__gcd(a,b)*b;
}

bool prime(int n)
{
	if(n<2)
		return false;
	for(int i=2 ; i<=sqrt(n) ; i++)
	{
		if(n%i == 0)
			return false;
	}
	return true;
}

/*int  power(int a, int b) {
 int rs = 1;
 while(b>0) {
  if(b & 1)
  {
    rs *= a;
    rs = rs%mod;
  }
  a = ((a%mod)*(a%mod))%mod;
  b >>= 1;
}
return rs%mod;
}*/

int power(int x, int y)
{
	if (y == 0)
		return 1;
	else if (y % 2 == 0)
		return (power(x, y/2)) * (power(x, (y) / 2));
	else
		return x * power(x, y / 2) * power(x, (y) / 2);
}

int log_a_to_base_b(int a, int b)
{
	if(b==1)
		return 0;
	return log(a) / log(b);
}

double kthRoot(double n, int k) {
	return pow(k, (1.0 / k) * (log(n) / log(k)));
}

int factorial(int n)
{
	if(n==0)
	{
		return 1;
	}
	return n*factorial(n-1);
}

bool compare(pii a,pii b)
{
	if(a.ff==b.ff)
		return a.ss<b.ss;
	else
		return a.ff<b.ff;
}

bool perfect(int n)
{
	float sr=sqrt(n);
	return ((sr-floor(sr))==0);
}

void solve()
{
	int n,res=INT_MAX;
	cin>>n;
	string s;
	cin>>s;
	if(n==1)
	{
		cout<<"0"<<endl;
		return;
	}
	vector<string> v;
	v.pb(s);
	for(int i=1 ; i<n ; i++)
	{
    string x=v[i-1];
    int l=x.size();
    string y = x.substr(0,l-1);
    string z = x[l-1]+y;
    v.pb(z);
	}
	f(i,v.size())
	{
		//cout<<v[i]<<" ";
		string x = v[i];
		f(k,11)
		{
			f(j,n)
			{
				int y = x[j]-'0';
				int z = (y+1)%10;
				x[j] = z+'0';
			}
			int ans=0;
			f(j,n)
			{
        int y = x[j]-'0';
        ans+=y*power(10,n-j-1);
			}
			res = min(res,ans);
		}
	}
	int cp=res,count=0;
	while(cp>0)
	{
		cp/=10;
		count++;
	}
	if(count<n)
	{
		f(i,n-count)cout<<"0";
	}
	cout<<res<<endl;
}

int32_t main()
{
	ish_8();
	//w(t)
	//{
		solve();
	//}
}


#include<bits/stdc++.h>
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define inf             1e18
#define ps(x,y)         cout<<fixed<<setprecision(y)<<x;
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
#define endl            "\n"
#define f(i,n)          for(int i=0 ; i<n ; i++)
#define SIZE            200000
#define mod             1000000007
#define mod1            1000003

void ish_8()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int lcm(int a,int b)
{
	return a/__gcd(a,b)*b;
}

bool prime(int n)
{
	if(n<2)
		return false;
	for(int i=2 ; i<=sqrt(n) ; i++)
	{
		if(n%i == 0)
			return false;
	}
	return true;
}

/*int  power(int a, int b) {
 int rs = 1;
 while(b>0) {
  if(b & 1)
  {
    rs *= a;
    rs = rs%mod;
  }
  a = ((a%mod)*(a%mod))%mod;
  b >>= 1;
}
return rs%mod;
}*/

int power(int x, int y)
{
	if (y == 0)
		return 1;
	else if (y % 2 == 0)
		return (power(x, y/2)) * (power(x, (y) / 2));
	else
		return x * power(x, y / 2) * power(x, (y) / 2);
}

int log_a_to_base_b(int a, int b)
{
	if(b==1)
		return 0;
	return log(a) / log(b);
}

double kthRoot(double n, int k) {
	return pow(k, (1.0 / k) * (log(n) / log(k)));
}

int factorial(int n)
{
	if(n==0)
	{
		return 1;
	}
	return n*factorial(n-1);
}

bool compare(pii a,pii b)
{
	if(a.ff==b.ff)
		return a.ss<b.ss;
	else
		return a.ff<b.ff;
}

bool perfect(int n)
{
	float sr=sqrt(n);
	return ((sr-floor(sr))==0);
}

void solve()
{
	int n,res=INT_MAX;
	cin>>n;
	string s;
	cin>>s;
	vector<string> v;
	v.pb(s);
	for(int i=1 ; i<n ; i++)
	{
    string x=v[i-1];
    int l=x.size();
    string y = x.substr(0,l-1);
    string z = x[l-1]+y;
    v.pb(z);
	}
	f(i,v.size())
	{
		//cout<<v[i]<<" ";
		string x = v[i];
		f(k,11)
		{
			f(j,x.size())
			{
				int y = x[j]-'0';
				int z = (y+1)%10;
				x[j] = z+'0';
			}
			int ans=0,m=x.size();
			f(j,x.size())
			{
        int y = x[j]-'0';
        ans+=y*power(10,m-j-1);
			}
			res = min(res,ans);
		}
	}
	int cp=res,count=0;
	while(cp>0)
	{
		cp/=10;
		count++;
	}
	if(count<n)
	{
		f(i,n-count)cout<<"0";
	}
	cout<<res<<endl;
}

int32_t main()
{
	ish_8();
	//w(t)
	//{
		solve();
	//}
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define endl '\n'
#define pii pair<int, int>
#define all(a) a.begin(),a.end()

template <typename T>
inline T gcd(T a, T b) { while (b != 0) swap(b, a %= b); return a; }

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;

    string ans = s;
    for(int i=0; i<n; ++i){
        int num = (s[i]=='0')?0:10-(s[i]-'0');
        string ts;
        for(int j=0; j<n; ++j){
            int ti = s[j]-'0';
            ti = (ti+num)%10;

            char c = (char)('0'+ti);
            ts += c;
        }

        string tans = ts.substr(i) + ts.substr(0, i);
        ans = min(ans, tans);
    }

    cout << ans;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define endl '\n'
#define pii pair<int, int>
#define all(a) a.begin(),a.end()

template <typename T>
inline T gcd(T a, T b) { while (b != 0) swap(b, a %= b); return a; }

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;

    string ans = s;
    for(int i=0; i<n; ++i){
        int num = (s[i]=='0')?0:9-(s[i]-'0');
        string ts;
        for(int j=0; j<n; ++j){
            int ti = s[j]-'0';
            ti = (ti+num)%9;

            char c = (char)('0'+ti);
            ts += c;
        }

        string tans = ts.substr(i) + ts.substr(0, i);
        ans = min(ans, tans);
    }

    cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
#define ll              long long
#define pb              push_back
#define mp              make_pair
#define ff              first
#define ss              second
#define LCM(x,y)        (((x)/__gcd((x),(y)))*(y))
#define PI              acos(-1)
#define SZ(x)           x.size() - 1
#define waa             puts("ripon")
#define mem(a,b)        memset(a,b,sizeof(a))
#define rep(i,a,n)      for(int i=(int)(a);i<=(int)(n);i++)
#define per(i,n,a)      for(int i=(int)(n);i>=(int)(a);i--)
#define all(v)          v.begin(), v.end()
#define allr(v)         v.rbegin(), v.rend()
int dx[] = { 0, 1, 0, -1, -1, 1, 1, -1 };
int dy[] = { 1, 0, -1, 0, -1, -1, 1, 1 };
int overlap(int rs,int re,int qs,int qe){ if(rs>qe or re<qs) return 0; else if(qs<=rs and re<=qe) return 1; else return 2;} // 0 no, 1 total, 2 partial
void pvec(auto v){for(auto x:v){cout<<x<<" ";}cout<<endl;}
//*************useless stuff*************//

#define TC 0
#define mod 10000007
#define N 1000000

void solve(int T) {

    int n;
    cin>>n;
    string str;
    cin>>str;

    string mn = str;

    rep(i,1,12){

        rep(j,0,SZ(str)){
            str[j]--;
            if(str[j]<'0') str[j] = '9';
        }

        rep(j,0,SZ(str)+1){
            mn = min(str,mn);
            rotate(str.rbegin(),str.rbegin()+1,str.rend());
        }

    }

    cout<<mn<<endl;

    return;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(nullptr);
    #ifdef LOCALDEF
        freopen("input.txt","r",stdin);
    #endif
    int T=1;
    if(TC) cin>>T;
    for(int t=1;t<=T;t++)   solve(t);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll              long long
#define pb              push_back
#define mp              make_pair
#define ff              first
#define ss              second
#define LCM(x,y)        (((x)/__gcd((x),(y)))*(y))
#define PI              acos(-1)
#define SZ(x)           x.size() - 1
#define waa             puts("ripon")
#define mem(a,b)        memset(a,b,sizeof(a))
#define rep(i,a,n)      for(int i=(int)(a);i<=(int)(n);i++)
#define per(i,n,a)      for(int i=(int)(n);i>=(int)(a);i--)
#define all(v)          v.begin(), v.end()
#define allr(v)         v.rbegin(), v.rend()
int dx[] = { 0, 1, 0, -1, -1, 1, 1, -1 };
int dy[] = { 1, 0, -1, 0, -1, -1, 1, 1 };
int overlap(int rs,int re,int qs,int qe){ if(rs>qe or re<qs) return 0; else if(qs<=rs and re<=qe) return 1; else return 2;} // 0 no, 1 total, 2 partial
void pvec(auto v){for(auto x:v){cout<<x<<" ";}cout<<endl;}
//*************useless stuff*************//

#define TC 0
#define mod 10000007
#define N 1000000

string reduce(string str){

    string ss  ="";

    rep(i,0,SZ(str)){

        char ch = --str[i];

        if(ch<'0') ch = '9';

        ss+=ch;

    }

    return ss;

}

int get(string str){

    int val = INT_MAX;

    rep(i,0,SZ(str)+2){
        rotate(str.begin(),str.begin()+1,str.end());
        int in = atoi(str.c_str());
        val = min(val,in);
    }

    return val;

}

void solve(int T) {
    int n;
    cin>>n;

    int res = INT_MAX;

    string str;
    cin>>str;

    rep(i,1,12){
        string tp = str;
        string ts = reduce(str);

        int val = get(ts);

        res = min(res,val);

        str = ts;

    }

    int tmm = res;
    int cnt = 0;

    while(tmm){
        cnt++;
        tmm/=10;
    }

    int tot = str.size() - cnt;

    rep(i,1,tot) cout<<0;

    cout<<res<<endl;

    return;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(nullptr);
    #ifdef LOCALDEF
        freopen("input.txt","r",stdin);
    #endif
    int T=1;
    if(TC) cin>>T;
    for(int t=1;t<=T;t++)   solve(t);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll              long long
#define pb              push_back
#define mp              make_pair
#define ff              first
#define ss              second
#define LCM(x,y)        (((x)/__gcd((x),(y)))*(y))
#define PI              acos(-1)
#define SZ(x)           x.size() - 1
#define waa             puts("ripon")
#define mem(a,b)        memset(a,b,sizeof(a))
#define rep(i,a,n)      for(int i=(int)(a);i<=(int)(n);i++)
#define per(i,n,a)      for(int i=(int)(n);i>=(int)(a);i--)
#define all(v)          v.begin(), v.end()
#define allr(v)         v.rbegin(), v.rend()
int dx[] = { 0, 1, 0, -1, -1, 1, 1, -1 };
int dy[] = { 1, 0, -1, 0, -1, -1, 1, 1 };
int overlap(int rs,int re,int qs,int qe){ if(rs>qe or re<qs) return 0; else if(qs<=rs and re<=qe) return 1; else return 2;} // 0 no, 1 total, 2 partial
void pvec(auto v){for(auto x:v){cout<<x<<" ";}cout<<endl;}
//*************useless stuff*************//

#define TC 0
#define mod 10000007
#define N 1000000

string reduce(string str){

    string ss  ="";

    rep(i,0,SZ(str)){

        char ch = --str[i];

        if(ch<'0') ch = '9';

        ss+=ch;

    }

    return ss;

}

int get(string str){

    int val = INT_MAX;

    rep(i,0,SZ(str)+2){
        rotate(str.rbegin(),str.rbegin()+1,str.rend());
        int in = atoi(str.c_str());
        val = min(val,in);
    }

    return val;

}

void solve(int T) {
    int n;
    cin>>n;

    int res = INT_MAX;

    string str;
    cin>>str;

    rep(i,1,12){
        string tp = str;
        string ts = reduce(str);
        int val = get(ts);
        res = min(res,val);
        str = ts;
    }

    int tmm = res;
    int cnt = 0;

    while(tmm){
        cnt++;
        tmm/=10;
    }

    int tot = str.size() - cnt;

    rep(i,1,tot) cout<<0;

    cout<<res<<endl;

    return;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(nullptr);
    #ifdef LOCALDEF
        freopen("input.txt","r",stdin);
    #endif
    int T=1;
    if(TC) cin>>T;
    for(int t=1;t<=T;t++)   solve(t);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll              long long
#define pb              push_back
#define mp              make_pair
#define ff              first
#define ss              second
#define LCM(x,y)        (((x)/__gcd((x),(y)))*(y))
#define PI              acos(-1)
#define SZ(x)           x.size() - 1
#define waa             puts("ripon")
#define mem(a,b)        memset(a,b,sizeof(a))
#define rep(i,a,n)      for(int i=(int)(a);i<=(int)(n);i++)
#define per(i,n,a)      for(int i=(int)(n);i>=(int)(a);i--)
#define all(v)          v.begin(), v.end()
#define allr(v)         v.rbegin(), v.rend()
int dx[] = { 0, 1, 0, -1, -1, 1, 1, -1 };
int dy[] = { 1, 0, -1, 0, -1, -1, 1, 1 };
int overlap(int rs,int re,int qs,int qe){ if(rs>qe or re<qs) return 0; else if(qs<=rs and re<=qe) return 1; else return 2;} // 0 no, 1 total, 2 partial
void pvec(auto v){for(auto x:v){cout<<x<<" ";}cout<<endl;}
//*************useless stuff*************//

#define TC 0
#define mod 10000007
#define N 1000000

string reduce(string str){

    string ss  ="";

    rep(i,0,SZ(str)){

        char ch = --str[i];

        if(ch<'0') ch = '9';

        ss+=ch;

    }

    return ss;

}

int get(string str){

    int val = INT_MAX;

    int sz = str.size() - 1;

    rep(i,0,SZ(str)+2){
        rotate(str.begin(),str.begin()+sz,str.end());
        int in = atoi(str.c_str());
        val = min(val,in);
    }

    return val;

}

void solve(int T) {
    int n;
    cin>>n;

    int res = INT_MAX;

    string str;
    cin>>str;

    rep(i,1,12){
        string tp = str;
        string ts = reduce(str);
        int val = get(ts);
        res = min(res,val);
        str = ts;
    }

    int tmm = res;
    int cnt = 0;

    while(tmm){
        cnt++;
        tmm/=10;
    }

    int tot = str.size() - cnt;

    rep(i,1,tot) cout<<0;

    cout<<res<<endl;

    return;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(nullptr);
    #ifdef LOCALDEF
        freopen("input.txt","r",stdin);
    #endif
    int T=1;
    if(TC) cin>>T;
    for(int t=1;t<=T;t++)   solve(t);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll              long long
#define pb              push_back
#define mp              make_pair
#define ff              first
#define ss              second
#define LCM(x,y)        (((x)/__gcd((x),(y)))*(y))
#define PI              acos(-1)
#define SZ(x)           x.size() - 1
#define waa             puts("ripon")
#define mem(a,b)        memset(a,b,sizeof(a))
#define rep(i,a,n)      for(int i=(int)(a);i<=(int)(n);i++)
#define per(i,n,a)      for(int i=(int)(n);i>=(int)(a);i--)
#define all(v)          v.begin(), v.end()
#define allr(v)         v.rbegin(), v.rend()
int dx[] = { 0, 1, 0, -1, -1, 1, 1, -1 };
int dy[] = { 1, 0, -1, 0, -1, -1, 1, 1 };
int overlap(int rs,int re,int qs,int qe){ if(rs>qe or re<qs) return 0; else if(qs<=rs and re<=qe) return 1; else return 2;} // 0 no, 1 total, 2 partial
void pvec(auto v){for(auto x:v){cout<<x<<" ";}cout<<endl;}
//*************useless stuff*************//

#define TC 0
#define mod 10000007
#define N 1000000

string reduce(string str){

    string ss  ="";

    rep(i,0,SZ(str)){

        char ch = --str[i];

        if(ch<'0') ch = '9';

        ss+=ch;

    }

    return ss;

}

int get(string str){

    int val = INT_MAX;

    rep(i,0,SZ(str)+2){
        rotate(str.rbegin(),str.rbegin()+1,str.rend());
        int in = atoi(str.c_str());
        val = min(val,in);
    }

    return val;

}

void solve(int T) {
    int n;
    cin>>n;

    int res = INT_MAX;

    string str;
    cin>>str;

    rep(i,1,12){
        string ts = reduce(str);
        int val = get(ts);
        res = min(res,val);
        str = ts;
    }

    int tmm = res;
    int cnt = 0;

    while(tmm){
        cnt++;
        tmm/=10;
    }

    if(res==0) cnt++;

    int tot = str.size() - cnt;

    rep(i,1,tot) cout<<0;

    cout<<res<<endl;

    return;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(nullptr);
    #ifdef LOCALDEF
        freopen("input.txt","r",stdin);
    #endif
    int T=1;
    if(TC) cin>>T;
    for(int t=1;t<=T;t++)   solve(t);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll              long long
#define pb              push_back
#define mp              make_pair
#define ff              first
#define ss              second
#define LCM(x,y)        (((x)/__gcd((x),(y)))*(y))
#define PI              acos(-1)
#define SZ(x)           x.size() - 1
#define waa             puts("ripon")
#define mem(a,b)        memset(a,b,sizeof(a))
#define rep(i,a,n)      for(int i=(int)(a);i<=(int)(n);i++)
#define per(i,n,a)      for(int i=(int)(n);i>=(int)(a);i--)
#define all(v)          v.begin(), v.end()
#define allr(v)         v.rbegin(), v.rend()
int dx[] = { 0, 1, 0, -1, -1, 1, 1, -1 };
int dy[] = { 1, 0, -1, 0, -1, -1, 1, 1 };
int overlap(int rs,int re,int qs,int qe){ if(rs>qe or re<qs) return 0; else if(qs<=rs and re<=qe) return 1; else return 2;} // 0 no, 1 total, 2 partial
void pvec(auto v){for(auto x:v){cout<<x<<" ";}cout<<endl;}
//*************useless stuff*************//

#define TC 0
#define mod 10000007
#define N 1000000

string reduce(string str){

    string ss  ="";

    rep(i,0,SZ(str)){

        char ch = --str[i];

        if(ch<'0') ch = '9';

        ss+=ch;

    }

    return ss;

}

int get(string str){

    int val = INT_MAX;

    rep(i,0,SZ(str)+2){
        rotate(str.begin(),str.begin()+1,str.end());
        int in = atoi(str.c_str());
        val = min(val,in);
    }

    return val;

}

void solve(int T) {
    int n;
    cin>>n;

    int res = INT_MAX;

    string str;
    cin>>str;

    rep(i,1,12){

        string ts = reduce(str);

        int val = get(ts);

        res = min(res,val);

        str = ts;

    }

    cout<<res<<endl;
    return;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(nullptr);
    #ifdef LOCALDEF
        freopen("input.txt","r",stdin);
    #endif
    int T=1;
    if(TC) cin>>T;
    for(int t=1;t<=T;t++)   solve(t);
    return 0;
}


#include <bits/stdc++.h>
#define lop(i,a,n) for(int i=a;i<n;i++)
#define ll long long int
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define M 1000000007
#define F first
#define S second
using namespace std;

//---------------------------------------------------------------------------------------

string add(string st,int n){
	string s=st;
	//cout<<"add"<<endl;
	for(int i=0;i<n;i++){
		s[i]=(((s[i]-'0')+1)%10)+'0';
	}
	return s;
}

string rot(string st,int n){
	string s=st;
	//cout<<"rot"<<endl;
	char c=s[n-1];
	for(int i=n-1;i>0;i--){
		s[i]=s[i-1];
	}
	s[0]=c;
	return s;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	#ifndef ONLINE_JUDGE
	freopen("D:\\codes\\input.txt", "r", stdin);
	freopen("D:\\codes\\output.txt", "w", stdout);
	#endif

    int n;
    cin>>n;
    string s;
    cin>>s;

    string ans=s;
    string s_up=s;
    for(int i=0;i<10;i++){

    	s_up=add(s_up,n);
    	cout<<s<<" "<<s_up<<'\n';
    	if(s_up<ans){
    		ans=s_up;
    		//cout<<"@"<<'\n';
    	}
    	string s_rot=s_up;
    	for(int j=0;j<n;j++){
    		s_rot=rot(s_rot,n);
    		//cout<<s_up<<'\n';
    		if(s_rot<ans){
    			ans=s_rot;
    			//cout<<"#"<<'\n';
    		}
    	}

    }
    cout<<ans<<'\n';

    return 0;
}


#include <bits/stdc++.h>
#define lop(i,a,n) for(int i=a;i<n;i++)
#define ll long long int
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define M 1000000007
#define F first
#define S second
using namespace std;

//---------------------------------------------------------------------------------------

string add(string st,int n){
	string s=st;
	//cout<<"add"<<endl;
	for(int i=0;i<n;i++){
		s[i]=(((s[i]-'0')+1)%10)+'0';
	}
	return s;
}

string rot(string st,int n){
	string s=st;
	//cout<<"rot"<<endl;
	char c=s[n-1];
	for(int i=n-1;i>0;i--){
		s[i]=s[i-1];
	}
	s[0]=c;
	return s;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	#ifndef ONLINE_JUDGE
	freopen("D:\\codes\\input.txt", "r", stdin);
	freopen("D:\\codes\\output.txt", "w", stdout);
	#endif

    int n;
    cin>>n;
    string s;
    cin>>s;

    string ans=s;
    string s_up=s;
    for(int i=0;i<10;i++){

    	s_up=add(s_up,n);
    	//cout<<s<<" "<<s_up<<'\n';
    	if(s_up<ans){
    		ans=s_up;
    		//cout<<"@"<<'\n';
    	}
    	string s_rot=s_up;
    	for(int j=0;j<n;j++){
    		s_rot=rot(s_rot,n);
    		//cout<<s_up<<'\n';
    		if(s_rot<ans){
    			ans=s_rot;
    			//cout<<"#"<<'\n';
    		}
    	}

    }
    cout<<ans<<'\n';

    return 0;
}


#include<bits/stdc++.h>
#define LL long long

using namespace std;

int n;
int a[12345];
int ans[12345];
void op_ar(int *ar, int num) {
    for(int i = 1; i <= num; ++i) {
        printf("%d", ar[i]);
        if(i == num) printf("\n");
        else printf(" ");
    }
}

int main() {
    int n;
    scanf("%d", &n); getchar();
    char c;
    for(int i = 1; i <= n; ++i) {
        scanf("%c", &c);
        a[i] = c - '0';
    }
    for(int i = 1; i <= n; ++i) ans[i] = 9;
    for(int i = n + 1; i <= 2 * n; ++i)
        a[i] = a[i - n];
    for(int i = 1; i <= 10; ++i) {
        int p1 = 1, p2 = 2, k = 0;
        while(p1 <= n && p2 <= n && k < n) {
            if(p1 == p2) p2++;
            if(a[p1 + k] == a[p2 + k]) k++;
            else if(a[p1 + k] < a[p2 + k])  {
                k = 0;
                p2 += k + 1;
            }
            else {
                k = 0;
                p1 += k + 1;
            }
        }
        int t = min(p1, p2);
        int ok = 0;
        for(int i = t; i < t + n; ++i) {
            if(a[i] > ans[i - t + 1]) break;
            if(a[i] < ans[i - t + 1]) {ok = 1; break;}
        }
        if(ok) for(int i = t; i < t + n; ++i) ans[i - t + 1] = a[i];
        for(int i = 1; i <= 2 * n; ++i) {
            a[i]--;
            if(a[i] < 0) a[i] += 10;
        }
        //for(int i = 1; i <= n; ++i) printf("%d", ans[i]);
        //printf(" %d \n", i);
    }
    for(int i = 1; i <= n; ++i) printf("%d", ans[i]);
    printf("\n");
    return 0;
}


#include<bits/stdc++.h>
#define LL long long

using namespace std;

int n;
char s[12345];

void op_ar(LL *ar, int num) {
    for(int i = 1; i <= num; ++i) {
        printf("%lld", ar[i]);
        if(i == num) printf("\n");
        else printf(" ");
    }
}

int main() {
    int n;
    scanf("%d", &n);
    scanf("%s", s + 1);
    int x, y;
    for(int i = n + 1; i <= 2 * n; ++i) s[i] = s[i - n];
    int i = 1, j = 2, k = 0;
    while(i <= n && j <= n && k < n) {
        if(i == j) j++;
        if((s[i + k] - s[i] + 10) % 10 == (s[j + k] - s[j] + 10) % 10) k++;
        else if((s[i + k] - s[i] + 10) % 10 < (s[j + k] - s[j] + 10) % 10) {
            j += k + 1;
            k = 0;
        }
        else {
            i += k + 1;
            k = 0;
        }
        x = i, y = j;
    }
    int t = min(x, y);
    for(int i = t; i < t + n; ++i)
        printf("%c", (s[i] - s[t] + 10) % 10 + '0');
    printf("\n");
    return 0;
}


#include<bits/stdc++.h>
#define LL long long

using namespace std;

int n;
char s[12345];

void op_ar(LL *ar, int num) {
    for(int i = 1; i <= num; ++i) {
        printf("%lld", ar[i]);
        if(i == num) printf("\n");
        else printf(" ");
    }
}

int main() {
    int n;
    scanf("%d", &n);
    scanf("%s", s + 1);
    int x, y;
    for(int i = n + 1; i <= 2 * n; ++i) s[i] = s[i - n];
    int i = 1, j = 2, k = 0;
    while(i <= n && j <= n && k < n) {
        if(i == j) j++;
        if((s[i + k + 1] - s[i + k] + 10) % 10 == (s[j + k + 1] - s[j + k] + 10) % 10) k++;
        else if((s[i + k + 1] - s[i + k] + 10) % 10 < (s[j + k + 1] - s[j + k] + 10) % 10) {
            j += k + 1;
            k = 0;
        }
        else {
            i += k + 1;
            k = 0;
        }
        x = i, y = j;
    }
    int t = min(x, y);
    for(int i = t; i < t + n; ++i)
        printf("%c", (s[i] - s[t] + 10) % 10 + '0');
    printf("\n");
    return 0;
}


#include<bits/stdc++.h>
#define LL long long

using namespace std;

int n;
char s[12345];

void op_ar(LL *ar, int num) {
    for(int i = 1; i <= num; ++i) {
        printf("%lld", ar[i]);
        if(i == num) printf("\n");
        else printf(" ");
    }
}

int main() {
    int n;
    scanf("%d", &n);
    scanf("%s", s + 1);
    int x, y;
    for(int i = n + 1; i <= 2 * n; ++i) s[i] = s[i - n];
    int i = 1, j = 2, k = 0;
    while(i <= n && j <= n && k < n) {
        if(i == j) j++;
        if((s[i + k + 1] - s[i] + 10) % 10 == (s[j + k + 1] - s[j] + 10) % 10) k++;
        else if((s[i + k + 1] - s[i] + 10) % 10 < (s[j + k + 1] - s[j] + 10) % 10) {
            j += k + 1;
            k = 0;
        }
        else {
            i += k + 1;
            k = 0;
        }
        x = i, y = j;
    }
    int t = min(x, y);
    for(int i = t; i < t + n; ++i)
        printf("%c", (s[i] - s[t] + 10) % 10 + '0');
    printf("\n");
    return 0;
}


#include<bits/stdc++.h>
#define LL long long

using namespace std;

int n;
int a[12345];
int ans[12345];
void op_ar(int *ar, int num) {
    for(int i = 1; i <= num; ++i) {
        printf("%d", ar[i]);
        if(i == num) printf("\n");
        else printf(" ");
    }
}

int main() {
    int n;
    scanf("%d", &n); getchar();
    char c;
    for(int i = 1; i <= n; ++i) {
        scanf("%c", &c);
        a[i] = c - '0';
    }
    for(int i = 1; i <= n; ++i) ans[i] = 9;
    for(int i = n + 1; i <= 2 * n; ++i)
        a[i] = a[i - n];
    for(int i = 1; i <= 10; ++i) {
        int p1 = 1, p2 = 2, k = 0;
        while(p1 <= n && p2 <= n && k < n) {
            if(a[p1 + k] == a[p2 + k]) k++;
            else if(a[p1 + k] < a[p2 + k])  {
                k = 0;
                p2 += k + 1;
            }
            else {
                k = 0;
                p1 += k + 1;
            }
        }
        int t = min(p1, p2);
        int ok = 0;
        for(int i = t; i < t + n; ++i) {
            if(a[i] > ans[i - t + 1]) break;
            if(a[i] < ans[i - t + 1]) {ok = 1; break;}
        }
        if(ok) for(int i = t; i < t + n; ++i) ans[i - t + 1] = a[i];
        for(int i = 1; i <= 2 * n; ++i) {
            a[i]--;
            if(a[i] < 0) a[i] += 10;
        }
    }
    for(int i = 1; i <= n; ++i) printf("%d", ans[i]);
    printf("\n");
    return 0;
}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define N 2*10e5
#define precise cout<<fixed<<setprecision(10)
#pragma GCC optimize("O0")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
#define rep(i,a,b) for(int i=a;i<b;i++)
#define min3(a,b,c) min(a,min(b,c))
#define nl cout<<"\n";
#define all(v) v.begin(),v.end()
#define F first
#define S second
typedef long long ll;
typedef vector<long long> vl;
typedef vector<pair<long,long>> vp;
void get(ll arr[],ll n){for(ll i=0;i<n;i++) cin>>arr[i];}
ll gcd(ll a,ll b);
ll binpow(ll a,ll b);
void solve()
{
	ll n;
	cin>>n;
	string x;
	cin>>x;
    x+= x[0];
	int mini=9,addf,num1;
	rep(i,0,n)
	{
		ll te= x[i]-'0';
		ll posi= x[i+1]-'0';
		if(te==0)
		{
			if(posi<mini) mini=posi,addf=0,num1=0;
		}
		else
		{
			if((10- te + posi)%10 < mini) mini = (10- te + posi)%10,addf=te,num1=10-te;
		}
	}
	vl v;
	rep(i,0,n)
	{
		if(x[i]-'0'==addf && abs(x[i]-x[i+1])==mini)
		v.pb(i);
	}
	vector<string> ans;string temp;
	rep(i,0,v.size())
	{
		temp.clear();
		ll s=v[i];
		for(ll j=s;j<n;j++)
		temp+= (x[j]-'0' +num1)%10 + '0';
		for(ll j=0;j<s;j++)
		temp+= (x[j]-'0' +num1)%10 + '0';
		ans.pb(temp);
	}
	sort(all(ans));
	cout<<ans[0];
}
int main()
{
 	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t;
	t=1;
	//cin>>t;
	while(t--)
	{
	 	solve();
	}
	//cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}
ll binpow(ll a, ll b) {
   ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define N 2*10e5
#define precise cout<<fixed<<setprecision(10)
#pragma GCC optimize("O0")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
#define rep(i,a,b) for(int i=a;i<b;i++)
#define min3(a,b,c) min(a,min(b,c))
#define nl cout<<"\n";
#define all(v) v.begin(),v.end()
#define F first
#define S second
typedef long long ll;
typedef vector<long long> vl;
typedef vector<pair<long,long>> vp;
void get(ll arr[],ll n){for(ll i=0;i<n;i++) cin>>arr[i];}
ll gcd(ll a,ll b);
ll binpow(ll a,ll b);
void solve()
{
	ll n;
	cin>>n;
	string x;
	cin>>x;
    string ans=x;
    string temp;
    rep(i,0,n)
    {
        temp.clear();
        ll add= 10 - (x[i]-'0');
        if(add==10) add=0;
        for(ll j=i;j<n;j++) temp+= (x[j]-'0' + add )%10 + '0';
        for(ll j=0;j<i;j++) temp+= (x[j]-'0' + add )%10 + '0';
        //cout<<temp;nl;
        if(ans.compare(temp)>0) ans=temp;
    }
    cout<<ans;
}
int main()
{
 	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t;
	t=1;
	//cin>>t;
	while(t--)
	{
	 	solve();
	}
	//cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}
ll binpow(ll a, ll b) {
   ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}


#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define N 2*10e5
#define precise cout<<fixed<<setprecision(10)
#pragma GCC optimize("O0")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
#define rep(i,a,b) for(int i=a;i<b;i++)
#define min3(a,b,c) min(a,min(b,c))
#define nl cout<<"\n";
#define all(v) v.begin(),v.end()
#define F first
#define S second
typedef long long ll;
typedef vector<long long> vl;
typedef vector<pair<long,long>> vp;
void get(ll arr[],ll n){for(ll i=0;i<n;i++) cin>>arr[i];}
ll gcd(ll a,ll b);
ll binpow(ll a,ll b);
void solve()
{
	ll n;
	cin>>n;
	string x;
	cin>>x;
	int mini=9,addf,num1;
	rep(i,0,n-1)
	{
		ll te= x[i]-'0';
		ll posi= x[i+1]-'0';
		if(te==0)
		{
			if(posi<mini) mini=posi,addf=0,num1=0;
		}
		else
		{
			if((10- te + posi)%10 < mini) mini = (10- te + posi)%10,addf=te,num1=10-te;
		}
	}
	ll te= x[n-1]-'0';
	ll posi= x[0]-'0';
	if(te==0)
	{
		if(posi<mini) mini=posi,addf=0,num1=0;
	}
	else
	{
		if((10- te + posi)%10 < mini) mini = (10- te + posi)%10,addf=te,num1=10-te;
	}
	vl v;
	//cout<<mini<<" "<<addf;
	rep(i,0,n-1)
	{
		if(x[i]-'0'==addf && abs(x[i]-x[i+1])==mini)
		v.pb(i);
	}
	if(x[n-1]-'0'==addf && abs(x[0]-x[n-1])==mini)
	v.pb(n-1);

	vector<string> ans;string temp;
	rep(i,0,v.size())
	{
		temp.clear();
		ll s=v[i];
		for(ll j=s;j<n;j++)
		temp+= (x[j]-'0' +num1)%10 + '0';
		for(ll j=0;j<s;j++)
		temp+= (x[j]-'0' +num1)%10 + '0';
		ans.pb(temp);
	}
	sort(all(ans));
	cout<<ans[0];
}
int main()
{
 	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t;
	t=1;
	//cin>>t;
	while(t--)
	{
	 	solve();
	}
	//cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}
ll binpow(ll a, ll b) {
   ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}


#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()

using namespace std;

typedef long long llong;

const llong MXN = 1e5 + 7;
const llong INF = 2e18 + 7;

inline void Need_for_speed()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

int n;
string s, ans;

int main()
{
  Need_for_speed();
  //freopen("Notail.in", "r", stdin);
  //freopen("Notail.out", "w", stdout);
  cin >> n >> s;
  sort(all(s));
  ans = s;
  for(int k = 1; k <= 10; k++){
    for(int j = 0; j < n; j++){
      int num = s[j] - '0';
      num = (num + 1) % 10;
      s[j] = char(num + '0');
    }
    sort(all(s));
    if(ans > s){
      ans = s;
    }
  }
  cout << ans;
}


#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()

using namespace std;

typedef long long llong;

const llong MXN = 1e5 + 7;
const llong INF = 2e18 + 7;

inline void Need_for_speed()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

int n;
string s, ans;

int main()
{
  Need_for_speed();
  //freopen("Notail.in", "r", stdin);
  //freopen("Notail.out", "w", stdout);
  cin >> n >> s;
  ans = s;
  for(int k = 1; k <= 10; k++){
    for(int j = 0; j < n; j++){
      int num = s[j] - '0';
      num = (num + 1) % 10;
      s[j] = char(num + '0');
    }
    for(int j = 0; j < n; j++){
      char ch = s[n - 1];
      s.erase(s.begin() + n - 1);
      s = ch + s;
      if(ans > s){
        ans = s;
      }
    }
  }
  cout << ans;
}


#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back
#define all(t) t.begin(),t.end()
#define fi first
#define se second
#define pii pair<int,int>

typedef long long ll;
typedef unsigned long long ull;
int const MAXN = 2000;

string min(string a, string b)
{
    for(int i = 0; i < a.size(); i++)
    {
        if(a[i] - '0' < b[i] - '0')
            return a;
        else if(a[i] - '0' > b[i] - '0')
            return b;
    }
    return a;
}

string getMinValue(string number)
{
    string result = number;
    for(int i = 0; i < number.size(); i++)
    {
        rotate(number.begin(), number.begin()+1, number.end());
        result = min(number, result);
    }
    return result;
}

string increase(string t)
{
    string s  = t;
    for(int i = 0; i < s.size(); i++)
    {
        if(s[i]-'0' != 9)
            s[i]++;
        else s[i] = '0';
    }
    return s;
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int n;
    cin >> n;
    string s;
    cin >> s;

    string result(s);
    for(int i = 0; i < 9; i++)
    {
        result = min(getMinValue(s), result);
        s = increase(s);
    }
    cout << result << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back
#define all(t) t.begin(),t.end()
#define fi first
#define se second
#define pii pair<int,int>

typedef long long ll;
typedef unsigned long long ull;
int const MAXN = 2000;

string min(string a, string b)
{
    for(int i = 0; i < a.size(); i++)
    {
        if(a[i] - '0' < b[i] - '0')
            return a;
        else if(a[i] - '0' > b[i] - '0')
            return b;
    }
    return a;
}

string getMinValue(string number)
{
    string result = number;
    for(int i = 0; i < number.size(); i++)
    {
        rotate(number.begin(), number.begin()+1, number.end());
        result = min(number, result);
    }
    return result;
}

string increase(string t)
{
    string s  = t;
    for(int i = 0; i < s.size(); i++)
    {
        if(s[i]-'0' != 9)
            s[i]++;
        else s[i] = '0';
    }
    return s;
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int n;
    cin >> n;
    string s;
    cin >> s;

    string result(s);
    for(int i = 0; i < 10; i++)
    {
        result = min(getMinValue(s), result);
        s = increase(s);
    }
    cout << result << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back
#define all(t) t.begin(),t.end()
#define fi first
#define se second
#define pii pair<int,int>

typedef long long ll;
typedef unsigned long long ull;
int const MAXN = 2000;

string getMinValue(string number)
{
    vector<int> v(10);
    for(int i = 0; i < number.size(); i++)
        v[number[i] - '0']++;

    string result;
    for(int i = 0; i < 10; i++)
        for(int j = 0; j < v[i]; j++)
             result += (char)(i+'0');
    return result;
}

string min(string a, string b)
{
    for(int i = 0; i < a.size(); i++)
    {
        if(a[i] - '0' < b[i] - '0')
            return a;
        else if(a[i] - '0' > b[i] - '0')
            return b;
    }
    return a;
}

string increase(string t)
{
    string s  = t;
    for(int i = 0; i < s.size(); i++)
    {
        if(s[i]-'0' != 9)
            s[i]++;
        else s[i] = '0';
    }
    return s;
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int n;
    cin >> n;
    string s;
    cin >> s;

    string result(s);
    for(int i = 0; i < 9; i++)
    {
        result = min(getMinValue(s), result);
        s = increase(s);
    }
    cout << result << endl;

    return 0;
}


#include <iostream>
#include <queue>
#include <string>
using namespace std;
int main(){
	int n;
	cin>>n;
	queue<int> q;
	string s;
	cin>>s;
	for(auto &c:s){
		q.push(c-'0');
	}
	queue<int> ans;
	ans.push(0);
	for(int i=2;i<=n;++i){
		ans.push(9);
	}
	for(int i=1;i<=n;++i){
		int f=(q.front()==0?0:10-q.front());
		int fa=(ans.front()==0?0:10-ans.front());
		queue<int> qt(q);
		queue<int> qa(ans);
		bool isMin=true;
		while(!qt.empty()){
			int nt=(qt.front()+f<=9?qt.front()+f:f-(10-qt.front()));
			int na=(qa.front()+fa<=9?qa.front()+fa:fa-(10-qa.front()));
		//	cout<<nt<<" "<<na<<"\n";
			qt.pop();
			qa.pop();
			if(nt>na){
				isMin=false;
				break;
			}else if(nt<na){
				break;
			}
		}
	//	cout<<"#"<<endl;
		if(isMin){
			ans=q;
		}
		q.push(q.front());
		q.pop();
	}
	int f=10-ans.front();
	while(!ans.empty()){
		int t=(ans.front()+f<=9?ans.front()+f:f-(10-ans.front()));
	//	int t=ans.front();
		ans.pop();
		if(t<0)	t+=10;
		cout<<t;
	}
	return 0;
}


#include <iostream>
#include <queue>
#include <string>
using namespace std;
int main(){
	int n;
	cin>>n;
	queue<int> q;
	string s;
	cin>>s;
	for(auto &c:s){
		q.push(c-'0');
	}
	queue<int> ans;
	for(int i=1;i<=n;++i){
		ans.push(9);
	}
	for(int i=1;i<=n;++i){
		int f=10-q.front();
		queue<int> qt(q);
		queue<int> qa(ans);
		bool isMin=true;
		while(!qt.empty()){
			int nt=(qt.front()+f<=9?qt.front()+f:f-(10-qt.front()));
			int na=(qa.front()+f<=9?qa.front()+f:f-(10-qa.front()));
			if(na<0)	na+=10;
			qt.pop();
			qa.pop();
			if(nt>na){
				isMin=false;
				break;
			}
		}
		if(isMin){
			ans=q;
		}
		q.push(q.front());
		q.pop();
	}
	int f=10-ans.front();
	while(!ans.empty()){
		int t=(ans.front()+f<=9?ans.front()+f:f-(10-ans.front()));
	//	int t=ans.front();
		ans.pop();
		if(t<0)	t+=10;
		cout<<t;
	}
	return 0;
}


#include <iostream>
#include <queue>
#include <string>
using namespace std;
int main(){
	int n;
	cin>>n;
	queue<int> q;
	string s;
	cin>>s;
	for(auto &c:s){
		q.push(c-'0');
	}
	queue<int> ans;
	ans.push(0);
	for(int i=2;i<=n;++i){
		ans.push(9);
	}
	for(int i=1;i<=n;++i){
		int f=(q.front()==0?0:10-q.front());
		int fa=(ans.front()==0?0:10-ans.front());
		queue<int> qt(q);
		queue<int> qa(ans);
		bool isMin=true;
		while(!qt.empty()){
			int nt=(qt.front()+f<=9?qt.front()+f:f-(10-qt.front()));
			int na=(qa.front()+fa<=9?qa.front()+fa:fa-(10-qa.front()));
	//		cout<<nt<<" "<<na<<"\n";
			qt.pop();
			qa.pop();
			if(nt>na){
				isMin=false;
				break;
			}
		}
	//	cout<<"#"<<endl;
		if(isMin){
			ans=q;
		}
		q.push(q.front());
		q.pop();
	}
	int f=10-ans.front();
	while(!ans.empty()){
		int t=(ans.front()+f<=9?ans.front()+f:f-(10-ans.front()));
	//	int t=ans.front();
		ans.pop();
		if(t<0)	t+=10;
		cout<<t;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n,p;
    cin>>n;
    char c[n],ch=345;
    for(int i=0;i<n;i++)
    {
        cin>>c[i];
        if(c[i]<ch)
            ch=c[i],p=i;
    }
    string ans;
    for(int i=p;i<n;i++)
        ans+=c[i];

    for(int i=0;i<p;i++)
        ans+=c[i];
    int x='9'-ch+1;
    for(int i=0;i<n;i++)
    {
        ans[i]+=x;
        if(ans[i]>'9')
        {
            ans[i]='0'+(ans[i]%58);
        }
    }
    cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;

char c[10000];
string func(char ch,int p,int n)
{
    string ans;
    for(int i=p;i<n;i++)
        ans+=c[i];
    for(int i=0;i<p;i++)
        ans+=c[i];
    int x='9'-ch+1;
    for(int i=0;i<n;i++)
    {
        ans[i]+=x;
        if(ans[i]>'9')
        {
            ans[i]='0'+(ans[i]%58);
        }
    }
    return ans;
}
int main()
{
    int n,p;
    cin>>n;
    char ch1='a',ch2='0'-1;
    string ans,x;
    for(int i=0;i<=n;i++)
        ans+='a';
    int p1,p2;
    for(int i=0;i<n;i++)
    {
        cin>>c[i];

        if(c[i]<ch1)
            ch1=c[i],p1=i;
        if(c[i]>ch2)
            ch2=c[i],p2=i;
    }
    for(int i=0;i<n;i++)
    {
        x=func(c[i],i,n);
        if(x<ans)
            ans=x;
    }
    x=func(ch1,p1,n);
    if(ans>x)
        ans=x;
    x=func(ch2,p2,n);
    if(ans>x)
        ans=x;
    cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;

char c[10000];
string func(char ch,int p,int n)
{
    string ans;
    for(int i=p;i<n;i++)
        ans+=c[i];
    for(int i=0;i<p;i++)
        ans+=c[i];
    int x='9'-ch+1;
    for(int i=0;i<n;i++)
    {
        ans[i]+=x;
        if(ans[i]>'9')
        {
            ans[i]='0'+(ans[i]%58);
        }
    }
    return ans;
}
int main()
{
    int n,p;
    cin>>n;
    char ch1='a',ch2='0'-1;
    string ans,x;
    for(int i=0;i<=n;i++)
        ans+='a';
    int p1,p2;
    for(int i=0;i<n;i++)
    {
        cin>>c[i];
        if(c[i]<ch1)
            ch1=c[i],p1=i;
        if(c[i]>ch2)
            ch2=c[i],p2=i;
    }
    x=func(ch1,p1,n);
    if(ans>x)
        ans=x;
    x=func(ch2,p2,n);
    if(ans>x)
        ans=x;
    cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n,p;
    cin>>n;
    char c[n],ch='a';
    for(int i=0;i<n;i++)
    {
        cin>>c[i];
        if(c[i]<ch)
            ch=c[i],p=i;
    }
    string ans;
    for(int i=p;i<n;i++)
        ans+=c[i];
    for(int i=0;i<p;i++)
        ans+=c[i];
    int x='9'-ch+1;
    for(int i=0;i<n;i++)
    {
        ans[i]+=x;
        if(ans[i]>'9')
        {
            ans[i]='0'+(ans[i]%58);
        }
    }
    cout<<ans;
}


#include <iostream>
#include <algorithm>
using namespace std;
int n;
int num[1010];
int cmp(int a[])
{
    for(int i = 0 ; i < n; i ++)
    {
        if(num[i] < a[i])
        {
            return 1;
        }
        else if(num[i] > a[i])
            return 0;
    }
    return 0;
}
int add(int a)
{
    a += 1;
    while(a >= 10) a -= 10;
    return a;
}
void sum()
{
    for(int i = 0; i < n; i ++)
        num[i] = add(num[i]);
}
void shift()
{
    int temp = num[n-1]; // to the right
    for(int i = n-1; i > 0; i--)
        num[i] = num[i-1];
    num[0] = temp;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    while(cin >> n) // input
    {
        int a;
        cin >> a;// array, not an int
        for(int i = n-1; i >= 0; i--)
        {
            num[i] = a % 10;
            a /= 10;
        }
        int ans[1010]; // ans needs to be initiallized
        for(int i = 0; i < n; i++)
            ans[i] = 9;
        for(int i = 0; i < n; i++) //calculate every sum while shifting
        {
            for(int j = 0; j < 10; j++)
            {
                sum();
                if(cmp(ans))
                {
                    for(int k = 0; k < n; k++) // mind the iterator
                        ans[k] = num[k];
                }
            }
            shift();
        }
        for(int i = 0; i < n; i++) // output
            cout << ans[i];
        cout << endl;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <memory>
using namespace std;
int n;
int num[1010];
int cmp(int a[])
{
    for(int i = 0 ; i < n; i ++)
    {
        if(num[i] < a[i])
        {
            return 1;
        }
        else if(num[i] > a[i])
            return 0;
    }
    return 0;
}
int add(int a)
{
    if(a== 9) return 0;
    else return a+1;
}
void sum()
{
    for(int i = 0; i < n; i ++)
        num[i] = add(num[i]);
}
void shift()
{
    int temp = num[n-1]; // to the right
    for(int i = n-1; i > 0; i--)
        num[i] = num[i-1];
    num[0] = temp;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n; // input
    char c = getchar(); // array, not an int
    for(int i = 0; i < n; i ++)
    {
        c = getchar();
        num[i] = c - '0';
    }
    int ans[1010]; // ans needs to be initiallized
    for(int i = 0; i < n; i++)
        ans[i] = num[i];
    for(int i = 0; i < n; i++) //calculate every sum while shifting
    {
        for(int j = 0; j < 10; j++)
        {
            sum();
            if(cmp(ans))
            {
                for(int k = 0; k < n; k++) // mind the iterator
                    ans[k] = num[k];
            }
        }
        shift();
    }
    for(int i = 0; i < n; i++) // output
        cout << ans[i];
    cout << endl;
    return 0;
}


#include<bits/stdc++.h>
//#define endl "\n"
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	//cin.tie(0);
	int n;
	cin>>n;
	string a;
	cin>>a;
	string ans=a,b=a;
	a+=a;
	for (int t=0; t<=9; t++)
	{
		for (int i=0; i<2*n; i++) a[i]='0'+(a[i]-'0'+1)%10;
		for (int i=0; i<n; i++)
		{
			int f=0;
			for (int j=i; j<i+n; j++)
			{
				b[f]=a[j];
				f++;
			}
			if (ans>b) ans=b;
		}
	}
	cout<<ans;
	return 0;
}


#include <cstdio>
#include <cstring>
using namespace std;
char a[2002];
char b[2002];
char r[2002];
int main(int argc, char const *argv[]) {
	int n; scanf("%d", &n);
	scanf(" %s", a);
	strcpy(r, a);
	for (int i = 0; i < n; ++i) {
		b[0] = '0';
		for (int j = 1; j < n; ++j) {
			b[j] = '0' + (a[(i+j)%n] - a[i] + 10) % 10;
		}
		if (strcmp(r, b) > 0) {
			strcpy(r, b);
		}
	}
	printf("%s\n", r);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

char s[10100];

void increase(char s[]) {
	for (int i = 0; s[i]; ++i) {
		if (s[i] == '9') {
			s[i] = '0';
		} else {
			s[i] += 1;
		}
	}
}

string calc(string s) {
	string ans = s;
	for (int i = 0; i < s.length(); ++i) {
		s += s[0];
		s.erase(0, 1);
		ans = min(ans, s);
	}
	return ans;
}

int main() {
	int n;
	scanf("%d", &n);
	scanf("%s", s);
	string ans = s;
	for (int i = 0; i < 9; ++i) {
		ans = min(ans, calc(s));
		increase(s);
	}
	printf("%s\n", ans.c_str());
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

char s[10100];

void increase(char s[]) {
	for (int i = 0; s[i]; ++i) {
		if (s[i] == '9') {
			s[i] = '0';
		} else {
			s[i] += 1;
		}
	}
}

string calc(string s) {
	string ans = s;
	for (int i = 0; i < s.length(); ++i) {
		s += s[0];
		s.erase(0, 1);
		ans = min(ans, s);
	}
	return ans;
}

int main() {
	int n;
	scanf("%d", &n);
	scanf("%s", s);
	string ans = s;
	for (int i = 0; i < 10; ++i) {
		ans = min(ans, calc(s));
		increase(s);
	}
	printf("%s\n", ans.c_str());
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define pb push_back

#define fr(i,a,b)   for(i=a;i<=b;i++)
#define frn(i,a,b)  for(i=a;i>=b;i--)
#define mem(arr,val)    memset(arr,val,sizeof(arr))
#define mp make_pair
#define pii pair<int,int>
#define F first
#define S second

string func(int mxind,string s2)
{
    string ss1,ss2,ans;
    int sz=s2.size();

    ss1=s2.substr(mxind,sz-mxind);
    if(mxind-1>=0)
        ss2=s2.substr(0,mxind);
    else
        ss2="";

    ans=ss1+ss2;

   // cout<<ans<<" "<<s2<<endl;

    return ans;

}

int main()
{
    //freopen("d://i.txt","r",stdin);
    //freopen("d://o.txt","w",stdout);
    int n,i,j,k,l,cnt=0,mxcnt=0,ind,mxind,premxCnt=0,zero=0,cc=0;
    string s,s2,s3,ans="bal",ss1,ss2;
    char ch,aft,mxaft,premxAft;

    cin>>n>>s;

    s2=s;
    s3="";
    while(s3!=s)
    {
        //    cout<<s2<<endl;
        zero=0;

        fr(i,0,s2.size()-1)
        {
            ch=s2[i];
            if(ch=='0') zero++;
            //s2.pb(ch);
        }

        if(zero>0)
        {
            int sz=s2.size(),flag=0;
            cnt=0;

              // cout<<s2<<endl;

            fr(i,0,sz-1)
            {

                if(s2[i]=='0')
                {
                    if(i+1<sz && s2[i]==s2[i+1])
                        cnt++;
                    else
                    {

                        ind=i-cnt;

                        cnt++;
                        //  cout<<cnt<<" "<<s2[i+2]<<" "<<ind<<endl;
                        if(cnt>mxcnt)
                            mxcnt=cnt, mxind=ind, mxaft=aft, ans=func(mxind,s2);
                        else if(cnt==mxcnt)
                        {
                            string preans=func(ind,s2);
                          //  cout<<ans<<" "<<preans<<endl;
                            for(j=0; j<n; j++)
                                if(ans[j]>preans[j])
                                {
                                    ans=preans;
                                    break;
                                }
                                else
                                {
                                   if(ans[j]==preans[j])
                                        continue;

                                   break;
                                }

                        }
                        cnt=0;
                    }
                }

            }
          //  cout<<ans<<endl;
            //     cout<<mxcnt<<" "<<mxind<<" "<<mxaft<<" "<<flag<<" "<<s2<<endl;

        }
        s3="";
        fr(i,0,s2.size()-1)
        {
            ch=(s2[i]=='9')? '0': s2[i]+1;
            s3.pb(ch);
        }
        s2=s3;
    }

    cout<<ans<<endl;

    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    string S;
    cin >> S;
    string ans = "";
    for(int i = 0; i < n; i++)
    {
        ans+='9';
    }
    for(int i = 0; i < 10; i++)
    {
        for(int j = 0; j < n; j++)
        {
            string now = "";
            for(int k = 0; k < n; k++)
            {
                now += (((S[(j+k)%n] + i - '0') % 10) + '0');
            }
            if(now < ans)
            {
                ans = now;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define pb push_back

#define fr(i,a,b)   for(i=a;i<=b;i++)
#define frn(i,a,b)  for(i=a;i>=b;i--)
#define mem(arr,val)    memset(arr,val,sizeof(arr))
#define mp make_pair
#define pii pair<int,int>
#define F first
#define S second

string func(int mxind,string s2)
{
    string ss1,ss2,ans;
    int sz=s2.size();

    ss1=s2.substr(mxind,sz-mxind);
    if(mxind-1>=0)
        ss2=s2.substr(0,mxind);
    else
        ss2="";

    ans=ss1+ss2;

   // cout<<ans<<" "<<s2<<endl;

    return ans;

}

int main()
{
    //freopen("d://i.txt","r",stdin);
    //freopen("d://o.txt","w",stdout);
    int n,i,j,k,l,cnt=0,mxcnt=0,ind,mxind,premxCnt=0,zero=0,cc=0;
    string s,s2,s3,ans="bal",ss1,ss2;
    char ch,aft,mxaft,premxAft;

    cin>>n>>s;

    s2=s;
    s3="";
    while(s3!=s)
    {
        //    cout<<s2<<endl;
        zero=0;

        fr(i,0,s2.size()-1)
        {
            ch=s2[i];
            if(ch=='0') zero++;
            //s2.pb(ch);
        }

        if(zero>0)
        {
            int sz=s2.size(),flag=0;
            cnt=0;

              // cout<<s2<<endl;

            fr(i,0,sz-1)
            {

                if(s2[i]=='0')
                {
                    if(i+1<sz && s2[i]==s2[i+1])
                        cnt++;
                    else
                    {

                        ind=i-cnt;

                        cnt++;
                        //  cout<<cnt<<" "<<s2[i+2]<<" "<<ind<<endl;
                        if(cnt>mxcnt)
                            mxcnt=cnt, mxind=ind, mxaft=aft, ans=func(mxind,s2);
                        else if(cnt==mxcnt)
                        {
                            string preans=func(ind,s2);
                          //  cout<<ans<<" "<<preans<<endl;
                           /* for(j=0; j<n; j++)
                                if(ans[j]>preans[j])
                                {
                                    ans=preans;
                                    break;
                                }
                                else
                                {
                                   if(ans[j]==preans[j])
                                        continue;

                                   break;
                                }*/
                            if(preans<ans)
                                ans=preans;

                        }
                        cnt=0;
                    }
                }

            }
          //  cout<<ans<<endl;
            //     cout<<mxcnt<<" "<<mxind<<" "<<mxaft<<" "<<flag<<" "<<s2<<endl;

        }
        s3="";
        fr(i,0,s2.size()-1)
        {
            ch=(s2[i]=='9')? '0': s2[i]+1;
            s3.pb(ch);
        }
        s2=s3;
    }

    cout<<ans<<endl;

    return 0;
}

/*
8
00240021

6
334477
001144

4
2014
0142

3
432
021

6
003001
001003

3
192
032

6 002300
000023

4 4932
0271

3 555
000

6 555999
000444
*/


#include <iostream>
using namespace std;
int main()
{
    int n,x,y;
    cin >> n;
    string S;
    cin >> S;
    string ans = "";
    for(int i = 0; i < n; i++)
    {
        ans+='9';
    }
    for(int i = 0; i < 10; i++)
    {
        for(int j = 0; j < n; j++)
        {
            string now = "";
            for(int k = 0; k < n; k++)
            {
                now += (((S[(j+k)%n] + i - '0') % 10) + '0');
            }

            for(x=0;x<n;x++)
            if(now[x]<ans[x])
            {
                ans = now;
                break;
            }
            else if(now[x]>ans[x])
                break;

        }
    }
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define pb push_back

#define fr(i,a,b)   for(i=a;i<=b;i++)
#define frn(i,a,b)  for(i=a;i>=b;i--)
#define mem(arr,val)    memset(arr,val,sizeof(arr))
#define mp make_pair
#define pii pair<int,int>
#define F first
#define S second

string func(int mxind,string s2)
{
    string ss1,ss2,ans;
    int sz=s2.size();

    ss1=s2.substr(mxind,sz-mxind);
    if(mxind-1>=0)
        ss2=s2.substr(0,mxind);
    else
        ss2="";

    ans=ss1+ss2;

   // cout<<ans<<" "<<s2<<endl;

    return ans;

}

int main()
{
    //freopen("d://i.txt","r",stdin);
    //freopen("d://o.txt","w",stdout);
    int n,i,j,k,l,cnt=0,mxcnt=0,ind,mxind,premxCnt=0,zero=0,cc=0;
    string s,s2,s3,ans="bal",ss1,ss2;
    char ch,aft,mxaft,premxAft;

    cin>>n>>s;

    s2=s;
    s3="";
    while(s3!=s)
    {
        //    cout<<s2<<endl;
        zero=0;

        fr(i,0,s2.size()-1)
        {
            ch=s2[i];
            if(ch=='0') zero++;
            //s2.pb(ch);
        }

        if(zero>0)
        {
            int sz=s2.size(),flag=0;
            cnt=0;

              // cout<<s2<<endl;

            fr(i,0,sz-1)
            {

                if(s2[i]=='0')
                {
                    if(i+1<sz && s2[i]==s2[i+1])
                        cnt++;
                    else
                    {

                        ind=i-cnt;

                        cnt++;
                        //  cout<<cnt<<" "<<s2[i+2]<<" "<<ind<<endl;
                        if(cnt>mxcnt)
                            mxcnt=cnt, mxind=ind, mxaft=aft, ans=func(mxind,s2);
                        else if(cnt==mxcnt)
                        {
                            string preans=func(ind,s2);
                          //  cout<<ans<<" "<<preans<<endl;
                            for(j=0; j<n; j++)
                                if(ans[j]>preans[j])
                                {
                                    ans=preans;
                                    break;
                                }
                                else
                                {
                                   if(ans[j]==preans[j])
                                        continue;

                                   break;
                                }

                        }
                        cnt=0;
                    }
                }

            }
          //  cout<<ans<<endl;
            //     cout<<mxcnt<<" "<<mxind<<" "<<mxaft<<" "<<flag<<" "<<s2<<endl;

        }
        s3="";
        fr(i,0,s2.size()-1)
        {
            ch=(s2[i]=='9')? '0': s2[i]+1;
            s3.pb(ch);
        }
        s2=s3;
    }

    cout<<ans<<endl;

    return 0;
}

/*
8
00240021

6
334477
001144

4
2014
0142

3
432
021

6
003001
001003

3
192
032

6 002300
000023

4 4932
0271

3 555
000

6 555999
000444
*/


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb push_back
#define pob pop_back
#define MP make_pair
#define MT make_tuple
#define rep(i,a,b) for(int i=a;i<b;i++)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define rept(it,v) for(auto it=v.begin();it!=v.end();it++)
#define pre(i,a,b) for(int i=a;i>=b;i--)
#define all(v) v.begin(),v.end()
#define F first
#define S seconda
#define sz(x) (int)x.size()
#define endl "\n"
#define ct continue
#define ub upper_bound
#define fill(a,b) memset(a,b,sizeof(a))
#define lb lower_bound
#define bs binary_search
#define pii pair<int,int>
bool sortbysec(pair<int,int> a, pair<int,int> b)
{
    if(a.second!=b.second) return a.second>b.second;
    else return a.first<b.first;
}
int main()
{ ll n,i,j,temp,sum,count,h,k;
    string ans,s;
    cin>>n;
    cin>>s;
    if(n==1)
    cout<<0;
    else
    {

    set<string> s1;

    for(j=0;j<n;j++)
    {  ans="";
        if(s[0]!='0')
        {
        k=10-(s[0]-'0');
        ans.pb('0');
        for(i=1;i<n;i++)
        {
          sum=s[i]-'0';
          sum=sum+k;
          sum%=10;
          string l=to_string(sum);
          ans.pb(l[0]);
        }
        }
        else
        {
            ans=s;
        }

        s1.insert(ans);
        h=s[0];
       for(i=0;i<n-1;i++)
       {
           s[i]=s[i+1];
       }
       s[n-1]=h;

    }
    auto it=s1.begin();
    cout<<(*it)<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb push_back
#define pob pop_back
#define MP make_pair
#define MT make_tuple
#define rep(i,a,b) for(int i=a;i<b;i++)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define rept(it,v) for(auto it=v.begin();it!=v.end();it++)
#define pre(i,a,b) for(int i=a;i>=b;i--)
#define all(v) v.begin(),v.end()
#define F first
#define S seconda
#define sz(x) (int)x.size()
#define endl "\n"
#define ct continue
#define ub upper_bound
#define fill(a,b) memset(a,b,sizeof(a))
#define lb lower_bound
#define bs binary_search
#define pii pair<int,int>
bool sortbysec(pair<int,int> a, pair<int,int> b)
{
    if(a.second!=b.second) return a.second>b.second;
    else return a.first<b.first;
}
int main()
{ ll n,i,j,temp,sum,count,h;
    string ans,s1;
    cin>>n;
    cin>>s1;
    if(n==1)
    cout<<0;
    else
    {
     vector<ll> v1,v;
    set<string> s;
    for(i=0;i<n-1;i++)
    {   h=s1[i+1]-s1[i];

        v1.pb(h);
    }
    for(i=0;i<v1.size();i++)
    {  count=0,j=i,ans="",sum=0;
    ans.pb('0');
        while(count<n-1)
        {
            j=j%(n-1);
            if(v1[j]>=0)
            {
                sum+=v1[j];
                sum=sum%10;

            }
            else
            {
              h=abs(v1[j]);
              sum=sum-h;
              if(sum<0)
              {
                  sum+=10;
              }

            }
           string  k=to_string(sum);

            ans.pb(k[0]);
            count++;
            j++;
        }

        s.insert(ans);
    }
    auto it=s.begin();
    cout<<(*it)<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb push_back
#define pob pop_back
#define MP make_pair
#define MT make_tuple
#define rep(i,a,b) for(int i=a;i<b;i++)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define rept(it,v) for(auto it=v.begin();it!=v.end();it++)
#define pre(i,a,b) for(int i=a;i>=b;i--)
#define all(v) v.begin(),v.end()
#define F first
#define S seconda
#define sz(x) (int)x.size()
#define endl "\n"
#define ct continue
#define ub upper_bound
#define fill(a,b) memset(a,b,sizeof(a))
#define lb lower_bound
#define bs binary_search
#define pii pair<int,int>
bool sortbysec(pair<int,int> a, pair<int,int> b)
{
    if(a.second!=b.second) return a.second>b.second;
    else return a.first<b.first;
}
int main()
{ ll n,i,j,temp,sum,count,h;
    string ans,s1;
    cin>>n;
    cin>>s1;

    vector<ll> v1,v;
    set<string> s;
    for(i=0;i<n-1;i++)
    {   h=s1[i+1]-s1[i];

        v1.pb(h);
    }
    for(i=0;i<v1.size();i++)
    {  count=0,j=i,ans="",sum=0;
    ans.pb('0');
        while(count<n-1)
        {
            j=j%(n-1);
            if(v1[j]>=0)
            {
                sum+=v1[j];
                sum=sum%10;

            }
            else
            {
              h=abs(v1[j]);
              sum=sum-h;
              if(sum<0)
              {
                  sum+=10;
              }

            }
           string  k=to_string(sum);

            ans.pb(k[0]);
            count++;
            j++;
        }

        s.insert(ans);
    }
    auto it=s.begin();
    cout<<(*it)<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define raftaar ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define in freopen("input.txt","r",stdin);
#define out freopen("output.txt","w",stdout);
#define sublime in out
#define rep(i,a,b) for (int i = a; i <= b; i++)
typedef long double ld;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#include <locale>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define N 100005
#define eps 1e-8
const int INF = 100005;
typedef pair<int,int> PII;
typedef vector<PII> VII;
#define all(c) (c).begin(),(c).end()
const long long LL_INF = (long long) 2e18 + 5;
inline int gcd(int a, int b) {
  return b == 0 ? a : gcd(b, a % b);
}
bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
  }
inline void solve(){
 int n,pos,pos1;
 string s;
 cin>>n>>s;
 int a[n];
 int a1[n];
 int mx=10;
 int mn=0;
 string x1="",x2="";
 for(int i=0;i<n;i++){
    a[i]=s[i]-'0';
    mx=min(a[i],mx);
    mn=max(a[i],mn);
 }
 int r=10-mx;
 int r1=10-mn;
 for(int i=0;i<n;i++){
    a[i]=(a[i]+r)%10;
    if(a[i]==0){
      pos=i;
    }
 }
  for(int i=0;i<n;i++){
    a1[i]=(a1[i]+r1)%10;
    if(a1[i]==0){
      pos1=i;
    }
 }
 for(int i=pos;i<n;i++){
  x1+=to_string(a[i]);
 }
 for(int i=0;i<pos;i++){
  x1+=to_string(a[i]);
 }
 for(int i=pos1;i<n;i++){
  x2+=to_string(a1[i]);
 }
 for(int i=0;i<pos1;i++){
  x2+=to_string(a1[i]);
 }
 if(x2<x1){
  cout<<x2;
 }
 else{
  cout<<x1;
 }

}

int main(){

  //sublime;
    raftaar;

      solve();

}


#include <bits/stdc++.h>
using namespace std;
#define raftaar ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define in freopen("input.txt","r",stdin);
#define out freopen("output.txt","w",stdout);
#define sublime in out
#define rep(i,a,b) for (int i = a; i <= b; i++)
typedef long double ld;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#include <locale>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define N 100005
#define eps 1e-8
const int INF = 100005;
typedef pair<int,int> PII;
typedef vector<PII> VII;
#define all(c) (c).begin(),(c).end()
const long long LL_INF = (long long) 2e18 + 5;
inline int gcd(int a, int b) {
  return b == 0 ? a : gcd(b, a % b);
}
bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
  }
inline void solve(){
 int n,pos,pos1;
 string s;
 cin>>n>>s;
 string ans = "ans";
    for (int i = 0; i < n; i++)
    {
        string t = "0";
        for (int j = 1; j < n; j++)
        {
            t += (char)((s[j] - s[0] + 10) % 10 + '0');
        }
        ans = min(ans, t);
        rotate(s.begin(), s.begin() + 1, s.end());
    }
    cout << ans;

}

int main(){

  //sublime;
    raftaar;

      solve();

}


#include <bits/stdc++.h>
using namespace std;
#define raftaar ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define in freopen("input.txt","r",stdin);
#define out freopen("output.txt","w",stdout);
#define sublime in out
#define rep(i,a,b) for (int i = a; i <= b; i++)
typedef long double ld;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#include <locale>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define N 100005
#define eps 1e-8
const int INF = 100005;
typedef pair<int,int> PII;
typedef vector<PII> VII;
#define all(c) (c).begin(),(c).end()
const long long LL_INF = (long long) 2e18 + 5;
inline int gcd(int a, int b) {
  return b == 0 ? a : gcd(b, a % b);
}
bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
  }
inline void solve(){
 int n,pos,pos1;
 string s;
 cin>>n>>s;
 int a[n];
 int a1[n];
 int mx=10;
 int mn=0;
 string x1="",x2="";
 for(int i=0;i<n;i++){
    a[i]=s[i]-'0';
    mx=min(a[i],mx);
    mn=max(a[i],mn);
 }
 int r=10-mx;
 int r1=10-mn;
 for(int i=0;i<n;i++){
    a[i]=(a[i]+r)%10;
    if(a[i]==0){
      pos=i;
    }
 }

  for(int i=0;i<n;i++){
    a1[i]=(a[i]+r1)%10;
    if(a1[i]==0){
      pos1=i;
    }
 }
 for(int i=pos;i<n;i++){
  x1+=to_string(a[i]);
 }
 for(int i=0;i<pos;i++){
  x1+=to_string(a[i]);
 }
 for(int i=pos1;i<n;i++){
  x2+=to_string(a1[i]);
 }
 for(int i=0;i<pos1;i++){
  x2+=to_string(a1[i]);
 }
 //cout<<x2<<" "<<x1<<" ";
 if(x2<x1){
  cout<<x2;
 }
 else{
  cout<<x1;
 }

}

int main(){

  //sublime;
    raftaar;

      solve();

}


#include <bits/stdc++.h>
using namespace std;
#define raftaar ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define in freopen("input.txt","r",stdin);
#define out freopen("output.txt","w",stdout);
#define sublime in out
#define rep(i,a,b) for (int i = a; i <= b; i++)
typedef long double ld;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#include <locale>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define N 100005
#define eps 1e-8
const int INF = 100005;
typedef pair<int,int> PII;
typedef vector<PII> VII;
#define all(c) (c).begin(),(c).end()
const long long LL_INF = (long long) 2e18 + 5;
inline int gcd(int a, int b) {
  return b == 0 ? a : gcd(b, a % b);
}
bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
  }
inline void solve(){
 int n,pos;
 string s;
 cin>>n>>s;
 int a[n];
 int mx=10;
 for(int i=0;i<n;i++){
    a[i]=s[i]-'0';
    mx=min(a[i],mx);
 }
 int r=10-mx;
 for(int i=0;i<n;i++){
    a[i]=(a[i]+r)%10;
    if(a[i]==0){
      pos=i;
    }
 }
 for(int i=pos;i<n;i++){
  cout<<a[i];
 }
 for(int i=0;i<pos;i++){
  cout<<a[i];
 }

}

int main(){

  //sublime;
    raftaar;

      solve();

}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    string ans,s,shifted_s;
    cin >> n >> s;
    ans = s;
    for(int i=0; i<10; ++i){
        for(int j=0;j<n;++j){
            s[j]=(s[j]-'0'+1)%10;
        }
        shifted_s=s+s;

        for(int k=0;k<n;k++)
            ans = min(ans, shifted_s.substr(k,n));
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    string ans,s,shifted_s;
    cin >> n >> s;
    ans = s;
    for(int i=0; i<10; ++i){
        for(int j=0;j<n;++j){
            s[j]=(s[j]-'0'+1)%10+'0';
        }
        shifted_s=s+s;

        for(int k=0;k<n;k++)
            ans = min(ans, shifted_s.substr(k,n));
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
#define mx 1001
using namespace std;
int n;
string best, s, ss;
int main(){
    cin >> n >> s;
    best = s;
    for(int i=0; i<10; ++i){
        for(int j=0;j<n;++j) s[j]=(s[j]-'0'+1)%10+'0';
        ss=s+s;
        for(int j=0;j<n;++j) best=min(best, ss.substr(j,n));
    }
    cout << best;
    return 0;
}


#include <iostream>
using namespace std;
int n, i, j;
string b, a, s;
int main(){
    cin >> n >> s;
    b = s;
    for(; i<10; ++i){
        for(j=0;j<n;++j) s[j]=(s[j]-'0'+1)%10+'0';
        a=s+s;
        for(j=0;j<n;++j) b=min(b, a.substr(j,n));
    }
    cout << b;
    return 0;
}


#include <bits/stdc++.h>
#define mx 1001
using namespace std;
int n;
string best,s;
string f(string s){
    s+=s;
    int best = 10, idx=-1, best_cnt=0, cnt=0;
    for(int i=0; i<s.size(); ++i){
        int d = s[i]-'0';
        if( d<best ){
            best = d;
            idx = i;
            best_cnt = cnt = 1;
        }else if( d==best ){
            ++cnt;
            if( cnt>best_cnt ){
                best_cnt = cnt;
                idx = i-cnt+1;
            }
        }else cnt = 0;
    }
    return s.substr( idx, s.size()/2 );
}
int main(){
    cin >> n >> s;
    best = s;
    for(int i=0; i<10; ++i){
        for(int j=0;j<s.length();++j) s[j]=(s[j]-'0'+1)%10+'0';
        best=min(best,f(s));
    }
    cout << best;
    return 0;
}