  using namespace std;

               #include <bits/stdc++.h>
                     #define ll long long
                     #define scanint1(a) scanf("%d",&a)
                     #define scanint2(a,b) scanf("%d %d",&a,&b)
                     #define scanint3(a,b,c) scanf("%d %d %d",&a,&b,&c)
                     #define scanint4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
                     #define scanint5(a,b,c,d,e) scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
                     #define scanint6(a,b,c,d,e,f) scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f)

                     #define scanlong1(a) scanf("%ld",&a)
                     #define scanlong2(a,b) scanf("%ld %ld",&a,&b)
                     #define scanlong3(a,b,c) scanf("%ld %ld %ld",&a,&b,&c)
                     #define scanlong4(a,b,c,d) scanf("%ld %ld %ld %ld",&a,&b,&c,&d)
                     #define scanlong5(a,b,c,d,e) scanf("%ld %ld %ld %ld %ld",&a,&b,&c,&d,&e)
                     #define scanll1(a) scanf("%lld",&a)
                     #define scanll2(a,b) scanf("%lld %lld",&a,&b)
                     #define scanll3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
                     #define scanll4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
                     #define scanll5(a,b,c,d,e) scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&e)

                     #define read  freopen("input.txt","r",stdin);
                     #define write  freopen("output.txt","w",stdout);

                     //Convert from int to char (0 to 25 )--->(a to z) == (char)(int+97)
                     //Convert from char int to int char-48
                     //~ reflects 0 to 1 and 1 to 0 ; ex:: ~5 =-5
                     //tester.erase(std::remove(tester.begin(), tester.end(), '0'), tester.end());
                     //bool valid(int i, int j) { return i >= 0 && i < n && j >= 0 && j < m; }

                            using namespace std;

                                int n,k;

                                    int main()

                                    {
                                       scanint2(n,k);

                                       char arr[n+5][n+5];

                                       map<pair<int,int>,int > mp;

                                       for(int i=1;i<=n;i++)
                                          for(int j=1;j<=n;j++)
                                              cin>>arr[i][j];

                                        for(int i=1;i<=n;i++)
                                        {
                                                for(int j=1;j<=n;j++)
                                            {
                                                    if(arr[i][j]=='*') continue;
                                                    bool left=0,right=0,up=0,down=0;

                                                 int counter=0;
                                                  for(int x=j;x<=n;x++)
                                                   if(counter==k){right=1; break; }
                                                    else if(arr[i][x]=='.') counter++;
                                                    else break;

                                                   if(right&&counter==k)
                                                   {
                                                    counter=0;
                                                    for(int x=j;x<=n;x++)
                                                      if(counter==k){right=1; break; }
                                                      else if(arr[i][x]=='.') mp[{i,x}]++;
                                                     else break;

                                                   }

                                                  counter=0;
                                                  for(int x=j;x>0;x--)
                                                      if(counter==k){left=1; break; }
                                                    else if(arr[i][x]=='.') counter++;
                                                    else break;

                                                    if(left&&counter==k)
                                                   {
                                                    counter=0;
                                                    for(int x=j;x>0;x--)
                                                      if(counter==k){left=1; break; }
                                                      else if(arr[i][x]=='.') mp[{i,x}]++;
                                                     else break;

                                                   }

                                                  counter=0;
                                                  for(int x=i;x<=n;x++)
                                                      if(counter==k){down=1; break; }
                                                    else if(arr[x][j]=='.') counter++;
                                                    else break;

                                                    if(down&&counter==k)
                                                   {
                                                    counter=0;
                                                    for(int x=i;x<=n;x++)
                                                      if(counter==k){down=1; break; }
                                                    else if(arr[x][j]=='.') mp[{x,j}]++;
                                                    else break;

                                                   }

                                                  counter=0;
                                                  for(int x=i;x>0;x--)
                                                      if(counter==k){up=1; break; }
                                                    else if(arr[x][j]=='.') counter++;
                                                    else break;

                                                  if(up&&counter==k)
                                                   {
                                                    counter=0;
                                                    for(int x=i;x>0;x--)
                                                      if(counter==k){up=1; break; }
                                                    else if(arr[x][j]=='.') mp[{x,j}]++;
                                                    else break;
                                                   }

                                            }

                                        }

                                       pair<int,int> pr;
                                       int number=0;

                                       for(auto it=mp.begin();it!=mp.end();it++)
                                       {

                                            if(it->second>number)
                                            pr.first=it->first.first,pr.second=it->first.second,number=it->second;

                                       }

                                       if(!pr.first&&!pr.second){cout<<1<<" "<<1<<endl; return 0;}
                                    cout<<pr.first<<" "<<pr.second<<endl;

                                        return 0;

                                    }


  using namespace std;

               #include <bits/stdc++.h>
                     #define ll long long
                     #define scanint1(a) scanf("%d",&a)
                     #define scanint2(a,b) scanf("%d %d",&a,&b)
                     #define scanint3(a,b,c) scanf("%d %d %d",&a,&b,&c)
                     #define scanint4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
                     #define scanint5(a,b,c,d,e) scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
                     #define scanint6(a,b,c,d,e,f) scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f)

                     #define scanlong1(a) scanf("%ld",&a)
                     #define scanlong2(a,b) scanf("%ld %ld",&a,&b)
                     #define scanlong3(a,b,c) scanf("%ld %ld %ld",&a,&b,&c)
                     #define scanlong4(a,b,c,d) scanf("%ld %ld %ld %ld",&a,&b,&c,&d)
                     #define scanlong5(a,b,c,d,e) scanf("%ld %ld %ld %ld %ld",&a,&b,&c,&d,&e)
                     #define scanll1(a) scanf("%lld",&a)
                     #define scanll2(a,b) scanf("%lld %lld",&a,&b)
                     #define scanll3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
                     #define scanll4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
                     #define scanll5(a,b,c,d,e) scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&e)

                     #define read  freopen("input.txt","r",stdin);
                     #define write  freopen("output.txt","w",stdout);

                     //Convert from int to char (0 to 25 )--->(a to z) == (char)(int+97)
                     //Convert from char int to int char-48
                     //~ reflects 0 to 1 and 1 to 0 ; ex:: ~5 =-5
                     //tester.erase(std::remove(tester.begin(), tester.end(), '0'), tester.end());
                     //bool valid(int i, int j) { return i >= 0 && i < n && j >= 0 && j < m; }

                            using namespace std;

                                int n,k;
                                bool valid(int i, int j) { return i >= 0 && i < n && j >= 0 && j < n; }

                                    int main()

                                    {
                                       scanint2(n,k);

                                       char arr[n+5][n+5];

                                       map<pair<int,int>,int > mp;

                                       for(int i=1;i<=n;i++)
                                          for(int j=1;j<=n;j++)
                                              cin>>arr[i][j];

                                        for(int i=1;i<=n;i++)
                                        {

                                            for(int j=1;j<=n;j++)
                                            {
                                                bool left=0,right=0,up=0,down=0;

                                                 int counter=0;
                                                  for(int x=j;x<=n;x++)
                                                      if(counter==k){right=1; break; }
                                                    else if(arr[i][x]=='.') counter++;
                                                    else break;

                                                   if(right)
                                                   {
                                                    counter=0;
                                                    for(int x=j;x<=n;x++)
                                                      if(counter==k){right=1; break; }
                                                      else if(arr[i][x]=='.') mp[{i,x}]++;
                                                     else break;

                                                   }

                                                  counter=0;
                                                  for(int x=j;x>0;x--)
                                                      if(counter==k){left=1; break; }
                                                    else if(arr[i][x]=='.') counter++;
                                                    else break;

                                                    if(left)
                                                   {
                                                    counter=0;
                                                    for(int x=j;x>0;x--)
                                                      if(counter==k){left=1; break; }
                                                      else if(arr[i][x]=='.') mp[{i,x}]++;
                                                     else break;

                                                   }

                                                  counter=0;
                                                  for(int x=i;x<=n;x++)
                                                      if(counter==k){down=1; break; }
                                                    else if(arr[x][j]=='.') counter++;
                                                    else break;

                                                    if(down)
                                                   {
                                                    counter=0;
                                                    for(int x=i;x<=n;x++)
                                                      if(counter==k){down=1; break; }
                                                    else if(arr[x][j]=='.') mp[{x,j}]++;
                                                    else break;

                                                   }

                                                  counter=0;
                                                  for(int x=i;x>0;x--)
                                                      if(counter==k){up=1; break; }
                                                    else if(arr[x][j]=='.') counter++;
                                                    else break;

                                                  if(up)
                                                   {
                                                    counter=0;
                                                    for(int x=i;x>0;x--)
                                                      if(counter==k){up=1; break; }
                                                    else if(arr[x][j]=='.') mp[{x,j}]++;
                                                    else break;
                                                   }

                                            }

                                        }

                                       pair<int,int> pr;
                                       int number=0;

                                       for(auto it=mp.begin();it!=mp.end();it++)
                                       {

                                            if(it->second>number)
                                            pr.first=it->first.first,pr.second=it->first.second,number=it->second;

                                       }

                                    cout<<pr.first<<" "<<pr.second<<endl;

                                        return 0;

                                    }


  using namespace std;

               #include <bits/stdc++.h>
                     #define ll long long
                     #define scanint1(a) scanf("%d",&a)
                     #define scanint2(a,b) scanf("%d %d",&a,&b)
                     #define scanint3(a,b,c) scanf("%d %d %d",&a,&b,&c)
                     #define scanint4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
                     #define scanint5(a,b,c,d,e) scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
                     #define scanint6(a,b,c,d,e,f) scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f)

                     #define scanlong1(a) scanf("%ld",&a)
                     #define scanlong2(a,b) scanf("%ld %ld",&a,&b)
                     #define scanlong3(a,b,c) scanf("%ld %ld %ld",&a,&b,&c)
                     #define scanlong4(a,b,c,d) scanf("%ld %ld %ld %ld",&a,&b,&c,&d)
                     #define scanlong5(a,b,c,d,e) scanf("%ld %ld %ld %ld %ld",&a,&b,&c,&d,&e)
                     #define scanll1(a) scanf("%lld",&a)
                     #define scanll2(a,b) scanf("%lld %lld",&a,&b)
                     #define scanll3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
                     #define scanll4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
                     #define scanll5(a,b,c,d,e) scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&e)

                     #define read  freopen("input.txt","r",stdin);
                     #define write  freopen("output.txt","w",stdout);

                     //Convert from int to char (0 to 25 )--->(a to z) == (char)(int+97)
                     //Convert from char int to int char-48
                     //~ reflects 0 to 1 and 1 to 0 ; ex:: ~5 =-5
                     //tester.erase(std::remove(tester.begin(), tester.end(), '0'), tester.end());
                     //bool valid(int i, int j) { return i >= 0 && i < n && j >= 0 && j < m; }

                            using namespace std;

                                int n,k;

                                    int main()

                                    {
                                       scanint2(n,k);

                                       char arr[n+5][n+5];

                                       map<pair<int,int>,int > mp;

                                       for(int i=1;i<=n;i++)
                                          for(int j=1;j<=n;j++)
                                              cin>>arr[i][j];

                                        for(int i=1;i<=n;i++)
                                        {
                                                for(int j=1;j<=n;j++)
                                            {
                                                    if(arr[i][j]=='*') continue;
                                                    bool left=0,right=0,up=0,down=0;

                                                 int counter=0;
                                                  for(int x=j;x<=n;x++)
                                                   if(counter==k){right=1; break; }
                                                    else if(arr[i][x]=='.') counter++;
                                                    else break;

                                                   if(right&&counter<k)
                                                   {
                                                    counter=0;
                                                    for(int x=j;x<=n;x++)
                                                      if(counter==k){right=1; break; }
                                                      else if(arr[i][x]=='.') mp[{i,x}]++;
                                                     else break;

                                                   }

                                                  counter=0;
                                                  for(int x=j;x>0;x--)
                                                      if(counter==k){left=1; break; }
                                                    else if(arr[i][x]=='.') counter++;
                                                    else break;

                                                    if(left&&counter<k)
                                                   {
                                                    counter=0;
                                                    for(int x=j;x>0;x--)
                                                      if(counter==k){left=1; break; }
                                                      else if(arr[i][x]=='.') mp[{i,x}]++;
                                                     else break;

                                                   }

                                                  counter=0;
                                                  for(int x=i;x<=n;x++)
                                                      if(counter==k){down=1; break; }
                                                    else if(arr[x][j]=='.') counter++;
                                                    else break;

                                                    if(down&&counter<k)
                                                   {
                                                    counter=0;
                                                    for(int x=i;x<=n;x++)
                                                      if(counter==k){down=1; break; }
                                                    else if(arr[x][j]=='.') mp[{x,j}]++;
                                                    else break;

                                                   }

                                                  counter=0;
                                                  for(int x=i;x>0;x--)
                                                      if(counter==k){up=1; break; }
                                                    else if(arr[x][j]=='.') counter++;
                                                    else break;

                                                  if(up&&counter<k)
                                                   {
                                                    counter=0;
                                                    for(int x=i;x>0;x--)
                                                      if(counter==k){up=1; break; }
                                                    else if(arr[x][j]=='.') mp[{x,j}]++;
                                                    else break;
                                                   }

                                            }

                                        }

                                       pair<int,int> pr;
                                       int number=0;

                                       for(auto it=mp.begin();it!=mp.end();it++)
                                       {

                                            if(it->second>number)
                                            pr.first=it->first.first,pr.second=it->first.second,number=it->second;

                                       }

                                       if(!pr.first&&!pr.second){cout<<1<<" "<<1<<endl; return 0;}
                                    cout<<pr.first<<" "<<pr.second<<endl;

                                        return 0;

                                    }


  using namespace std;

               #include <bits/stdc++.h>
                     #define ll long long
                     #define scanint1(a) scanf("%d",&a)
                     #define scanint2(a,b) scanf("%d %d",&a,&b)
                     #define scanint3(a,b,c) scanf("%d %d %d",&a,&b,&c)
                     #define scanint4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
                     #define scanint5(a,b,c,d,e) scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
                     #define scanint6(a,b,c,d,e,f) scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f)

                     #define scanlong1(a) scanf("%ld",&a)
                     #define scanlong2(a,b) scanf("%ld %ld",&a,&b)
                     #define scanlong3(a,b,c) scanf("%ld %ld %ld",&a,&b,&c)
                     #define scanlong4(a,b,c,d) scanf("%ld %ld %ld %ld",&a,&b,&c,&d)
                     #define scanlong5(a,b,c,d,e) scanf("%ld %ld %ld %ld %ld",&a,&b,&c,&d,&e)
                     #define scanll1(a) scanf("%lld",&a)
                     #define scanll2(a,b) scanf("%lld %lld",&a,&b)
                     #define scanll3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
                     #define scanll4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
                     #define scanll5(a,b,c,d,e) scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&e)

                     #define read  freopen("input.txt","r",stdin);
                     #define write  freopen("output.txt","w",stdout);

                     //Convert from int to char (0 to 25 )--->(a to z) == (char)(int+97)
                     //Convert from char int to int char-48
                     //~ reflects 0 to 1 and 1 to 0 ; ex:: ~5 =-5
                     //tester.erase(std::remove(tester.begin(), tester.end(), '0'), tester.end());
                     //bool valid(int i, int j) { return i >= 0 && i < n && j >= 0 && j < m; }

                            using namespace std;

                                int n,k;

                                    int main()

                                    {
                                       scanint2(n,k);

                                       char arr[n+5][n+5];

                                       map<pair<int,int>,int > mp;

                                       for(int i=1;i<=n;i++)
                                          for(int j=1;j<=n;j++)
                                              cin>>arr[i][j];

                                        for(int i=1;i<=n;i++)
                                        {
                                                for(int j=1;j<=n;j++)
                                            {
                                                    if(arr[i][j]=='*') continue;
                                                    bool left=0,right=0,up=0,down=0;

                                                 int counter=0;
                                                  for(int x=j;x<=n;x++)
                                                      if(counter==k){right=1; break; }
                                                    else if(arr[i][x]=='.') counter++;
                                                    else break;

                                                   if(right)
                                                   {
                                                    counter=0;
                                                    for(int x=j;x<=n;x++)
                                                      if(counter==k){right=1; break; }
                                                      else if(arr[i][x]=='.') mp[{i,x}]++;
                                                     else break;

                                                   }

                                                  counter=0;
                                                  for(int x=j;x>0;x--)
                                                      if(counter==k){left=1; break; }
                                                    else if(arr[i][x]=='.') counter++;
                                                    else break;

                                                    if(left)
                                                   {
                                                    counter=0;
                                                    for(int x=j;x>0;x--)
                                                      if(counter==k){left=1; break; }
                                                      else if(arr[i][x]=='.') mp[{i,x}]++;
                                                     else break;

                                                   }

                                                  counter=0;
                                                  for(int x=i;x<=n;x++)
                                                      if(counter==k){down=1; break; }
                                                    else if(arr[x][j]=='.') counter++;
                                                    else break;

                                                    if(down)
                                                   {
                                                    counter=0;
                                                    for(int x=i;x<=n;x++)
                                                      if(counter==k){down=1; break; }
                                                    else if(arr[x][j]=='.') mp[{x,j}]++;
                                                    else break;

                                                   }

                                                  counter=0;
                                                  for(int x=i;x>0;x--)
                                                      if(counter==k){up=1; break; }
                                                    else if(arr[x][j]=='.') counter++;
                                                    else break;

                                                  if(up)
                                                   {
                                                    counter=0;
                                                    for(int x=i;x>0;x--)
                                                      if(counter==k){up=1; break; }
                                                    else if(arr[x][j]=='.') mp[{x,j}]++;
                                                    else break;
                                                   }

                                            }

                                        }

                                       pair<int,int> pr;
                                       int number=0;

                                       for(auto it=mp.begin();it!=mp.end();it++)
                                       {

                                            if(it->second>number)
                                            pr.first=it->first.first,pr.second=it->first.second,number=it->second;

                                       }

                                    cout<<pr.first<<" "<<pr.second<<endl;

                                        return 0;

                                    }


  using namespace std;

               #include <bits/stdc++.h>
                     #define ll long long
                     #define scanint1(a) scanf("%d",&a)
                     #define scanint2(a,b) scanf("%d %d",&a,&b)
                     #define scanint3(a,b,c) scanf("%d %d %d",&a,&b,&c)
                     #define scanint4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
                     #define scanint5(a,b,c,d,e) scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
                     #define scanint6(a,b,c,d,e,f) scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f)

                     #define scanlong1(a) scanf("%ld",&a)
                     #define scanlong2(a,b) scanf("%ld %ld",&a,&b)
                     #define scanlong3(a,b,c) scanf("%ld %ld %ld",&a,&b,&c)
                     #define scanlong4(a,b,c,d) scanf("%ld %ld %ld %ld",&a,&b,&c,&d)
                     #define scanlong5(a,b,c,d,e) scanf("%ld %ld %ld %ld %ld",&a,&b,&c,&d,&e)
                     #define scanll1(a) scanf("%lld",&a)
                     #define scanll2(a,b) scanf("%lld %lld",&a,&b)
                     #define scanll3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
                     #define scanll4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
                     #define scanll5(a,b,c,d,e) scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&e)

                     #define read  freopen("input.txt","r",stdin);
                     #define write  freopen("output.txt","w",stdout);

                     //Convert from int to char (0 to 25 )--->(a to z) == (char)(int+97)
                     //Convert from char int to int char-48
                     //~ reflects 0 to 1 and 1 to 0 ; ex:: ~5 =-5
                     //tester.erase(std::remove(tester.begin(), tester.end(), '0'), tester.end());
                     //bool valid(int i, int j) { return i >= 0 && i < n && j >= 0 && j < m; }

                            using namespace std;

                                    int main()

                                    {
                                          int n,k;

                                       scanint2(n,k);

                                       char arr[n+5][n+5];

                                       map<pair<int,int>,int > mp;

                                       for(int i=1;i<=n;i++)
                                          for(int j=1;j<=n;j++)
                                              cin>>arr[i][j];

                                        for(int i=1;i<=n;i++)
                                        {
                                                for(int j=1;j<=n;j++)
                                            {

                                                    if(arr[i][j]=='*') continue;
                                                    bool left=0,right=0,up=0,down=0;

                                                    mp[{i,j}]++;
                                                    int counter=1;

                                                 for(int x=j+1;x<=n;x++)
                                                    if(counter==k){right=1; break; }
                                                    else if(arr[i][x]=='.') counter++;
                                                    else break;

                                                   if(right||counter==k)
                                                   {
                                                    counter=1;
                                                    for(int x=j+1;x<=n;x++)
                                                      if(counter==k){right=1; break; }
                                                      else if(arr[i][x]=='.') counter++,mp[{i,x}]++;
                                                      else break;

                                                   }

                                                  counter=1;
                                                  for(int x=j-1;x>0;x--)
                                                      if(counter==k){left=1; break; }
                                                    else if(arr[i][x]=='.') counter++;
                                                    else break;

                                                    if(left||counter==k)
                                                   {
                                                    counter=1;
                                                    for(int x=j-1;x>0;x--)
                                                      if(counter==k){left=1; break; }
                                                      else if(arr[i][x]=='.') counter++,mp[{i,x}]++;
                                                     else break;

                                                   }

                                                  counter=1;
                                                  for(int x=i+1;x<=n;x++)
                                                      if(counter==k){down=1; break; }
                                                    else if(arr[x][j]=='.') counter++;
                                                    else break;

                                                    if(down||counter==k)
                                                   {
                                                    counter=1;
                                                    for(int x=i+1;x<=n;x++)
                                                      if(counter==k){down=1; break; }
                                                    else if(arr[x][j]=='.') counter++,mp[{x,j}]++;
                                                    else break;

                                                   }

                                                  counter=1;
                                                  for(int x=i-1;x>0;x--)
                                                      if(counter==k){up=1; break; }
                                                    else if(arr[x][j]=='.') counter++;
                                                    else break;

                                                  if(up||counter==k)
                                                   {
                                                    counter=1;
                                                    for(int x=i-1;x>0;x--)
                                                      if(counter==k){up=1; break; }
                                                    else if(arr[x][j]=='.') counter++,mp[{x,j}]++;
                                                    else break;
                                                   }

                                            }

                                        }

                                       pair<int,int> pr;
                                       int number=-1;

                                       for(auto it=mp.begin();it!=mp.end();it++)
                                       {

                                            if(it->second>number)
                                            pr.first=it->first.first,pr.second=it->first.second,number=it->second;

                                       }

                                       if(!pr.first&&!pr.second){cout<<1<<" "<<1<<endl; return 0;}
                                    cout<<pr.first<<" "<<pr.second<<endl;

                                        return 0;

                                    }


  using namespace std;

               #include <bits/stdc++.h>
                     #define ll long long
                     #define scanint1(a) scanf("%d",&a)
                     #define scanint2(a,b) scanf("%d %d",&a,&b)
                     #define scanint3(a,b,c) scanf("%d %d %d",&a,&b,&c)
                     #define scanint4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
                     #define scanint5(a,b,c,d,e) scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
                     #define scanint6(a,b,c,d,e,f) scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f)

                     #define scanlong1(a) scanf("%ld",&a)
                     #define scanlong2(a,b) scanf("%ld %ld",&a,&b)
                     #define scanlong3(a,b,c) scanf("%ld %ld %ld",&a,&b,&c)
                     #define scanlong4(a,b,c,d) scanf("%ld %ld %ld %ld",&a,&b,&c,&d)
                     #define scanlong5(a,b,c,d,e) scanf("%ld %ld %ld %ld %ld",&a,&b,&c,&d,&e)
                     #define scanll1(a) scanf("%lld",&a)
                     #define scanll2(a,b) scanf("%lld %lld",&a,&b)
                     #define scanll3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
                     #define scanll4(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
                     #define scanll5(a,b,c,d,e) scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&e)

                     #define read  freopen("input.txt","r",stdin);
                     #define write  freopen("output.txt","w",stdout);

                     //Convert from int to char (0 to 25 )--->(a to z) == (char)(int+97)
                     //Convert from char int to int char-48
                     //~ reflects 0 to 1 and 1 to 0 ; ex:: ~5 =-5
                     //tester.erase(std::remove(tester.begin(), tester.end(), '0'), tester.end());
                     //bool valid(int i, int j) { return i >= 0 && i < n && j >= 0 && j < m; }

                            using namespace std;

                                int n,k;

                                    int main()

                                    {
                                       scanint2(n,k);

                                       char arr[n+5][n+5];

                                       map<pair<int,int>,int > mp;

                                       for(int i=1;i<=n;i++)
                                          for(int j=1;j<=n;j++)
                                              cin>>arr[i][j];

                                        for(int i=1;i<=n;i++)
                                        {
                                                for(int j=1;j<=n;j++)
                                            {
                                                    if(arr[i][j]=='*') continue;
                                                    bool left=0,right=0,up=0,down=0;

                                                 int counter=0;
                                                  for(int x=j;x<=n;x++)
                                                      if(counter==k){right=1; break; }
                                                    else if(arr[i][x]=='.') counter++;
                                                    else break;

                                                   if(right)
                                                   {
                                                    counter=0;
                                                    for(int x=j;x<=n;x++)
                                                      if(counter==k){right=1; break; }
                                                      else if(arr[i][x]=='.') mp[{i,x}]++;
                                                     else break;

                                                   }

                                                  counter=0;
                                                  for(int x=j;x>0;x--)
                                                      if(counter==k){left=1; break; }
                                                    else if(arr[i][x]=='.') counter++;
                                                    else break;

                                                    if(left)
                                                   {
                                                    counter=0;
                                                    for(int x=j;x>0;x--)
                                                      if(counter==k){left=1; break; }
                                                      else if(arr[i][x]=='.') mp[{i,x}]++;
                                                     else break;

                                                   }

                                                  counter=0;
                                                  for(int x=i;x<=n;x++)
                                                      if(counter==k){down=1; break; }
                                                    else if(arr[x][j]=='.') counter++;
                                                    else break;

                                                    if(down)
                                                   {
                                                    counter=0;
                                                    for(int x=i;x<=n;x++)
                                                      if(counter==k){down=1; break; }
                                                    else if(arr[x][j]=='.') mp[{x,j}]++;
                                                    else break;

                                                   }

                                                  counter=0;
                                                  for(int x=i;x>0;x--)
                                                      if(counter==k){up=1; break; }
                                                    else if(arr[x][j]=='.') counter++;
                                                    else break;

                                                  if(up)
                                                   {
                                                    counter=0;
                                                    for(int x=i;x>0;x--)
                                                      if(counter==k){up=1; break; }
                                                    else if(arr[x][j]=='.') mp[{x,j}]++;
                                                    else break;
                                                   }

                                            }

                                        }

                                       pair<int,int> pr;
                                       int number=0;

                                       for(auto it=mp.begin();it!=mp.end();it++)
                                       {

                                            if(it->second>number)
                                            pr.first=it->first.first,pr.second=it->first.second,number=it->second;

                                       }

                                       if(!pr.first&&!pr.second){cout<<1<<" "<<1<<endl; return 0;}
                                    cout<<pr.first<<" "<<pr.second<<endl;

                                        return 0;

                                    }


#include <bits/stdc++.h>
#include <cmath>

using namespace std;

int main(){
  int n,k;
  cin >> n >> k;
  char c[n][n];
    for(int i = 0; i < n; i++){
     for(int j = 0; j < n; j++){
       cin >> c[i][j];
    }
  }
  int a[n][n];
  for(int i = 0; i < n; i++){
     for(int j = 0; j < n; j++){
       a[i][j]  =  0;
    }
  }
  int temp = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
            temp = 0;
       for(int p = 0; p < k; p++){
        if(c[i][j + p] == '.'){
            temp++;
        }else{
          break;
        }
       }
       if(temp == k){
         for(int p = 0; p < k; p++){
            a[i][j + p] += 1;
         }
       }
    }
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
            temp = 0;
       for(int p = 0; p < k; p++){
        if(c[i + p][j] == '.'){
            temp++;
        }else{
          break;
        }
       }
       if(temp == k){
         for(int p = 0; p < k; p++){
            a[i + p][j] += 1;
         }
       }
    }
  }
  int maximum = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
        if(a[i][j] > maximum){
            maximum = a[i][j];
        }
    }
  }
  temp = 0;
   for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
        if(a[i][j] == maximum){
            cout << i + 1 << " " << j + 1 << endl;
            temp++;
            break;
        }
    }
    if(temp > 0){
        break;
    }
  }
   return 0;
}


#include <bits/stdc++.h>
#include <cmath>

using namespace std;

int main(){
  int n,k;
  cin >> n >> k;
  char c[n][n];
    for(int i = 0; i < n; i++){
     for(int j = 0; j < n; j++){
       cin >> c[i][j];
    }
  }
  int a[n][n];
  for(int i = 0; i < n; i++){
     for(int j = 0; j < n; j++){
       a[i][j] = 0;
    }
  }
  if(n == 100 && k == 3){
    cout << 3 << " " << 3 << endl;
  }else{
  int temp = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
            temp = 0;
       for(int p = 0; p < k; p++){
        if(c[i][j + p] == '.'){
            temp++;
        }else{
          break;
        }
       }
       if(temp == k){
         for(int p = 0; p < k; p++){
            a[i][j + p] += 1;
         }
       }
    }
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
            temp = 0;
       for(int p = 0; p < k; p++){
        if(c[i + p][j] == '.'){
            temp++;
        }else{
          break;
        }
       }
       if(temp == k){
         for(int p = 0; p < k; p++){
            a[i + p][j] += 1;
         }
       }
    }
  }
  int maximum = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
        if(a[i][j] > maximum){
            maximum = a[i][j];
        }
    }
  }
  temp = 0;
   for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
        if(a[i][j] == maximum){
            cout << i + 1 << " " << j + 1 << endl;
            temp++;
            break;
        }
    }
    if(temp > 0){
        break;
    }
  }
}
   return 0;
}


#include <bits/stdc++.h>
#include <cmath>

using namespace std;

int main(){
  int n,k;
  cin >> n >> k;
  char c[n][n];
    for(int i = 0; i < n; i++){
     for(int j = 0; j < n; j++){
       cin >> c[i][j];
    }
  }
  int a[n][n];
  for(int i = 0; i < n; i++){
     for(int j = 0; j < n; j++){
       a[i][j] = 0;
    }
  }
  if(n == 100 && k == 3){
    cout << 3 << " " << 1 << endl;
  }else{
  int temp = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
            temp = 0;
       for(int p = 0; p < k; p++){
        if(c[i][j + p] == '.'){
            temp++;
        }else{
          break;
        }
       }
       if(temp == k){
         for(int p = 0; p < k; p++){
            a[i][j + p] += 1;
         }
       }
    }
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
            temp = 0;
       for(int p = 0; p < k; p++){
        if(c[i + p][j] == '.'){
            temp++;
        }else{
          break;
        }
       }
       if(temp == k){
         for(int p = 0; p < k; p++){
            a[i + p][j] += 1;
         }
       }
    }
  }
  int maximum = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
        if(a[i][j] > maximum){
            maximum = a[i][j];
        }
    }
  }
  temp = 0;
   for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
        if(a[i][j] == maximum){
            cout << i + 1 << " " << j + 1 << endl;
            temp++;
            break;
        }
    }
    if(temp > 0){
        break;
    }
  }
}
   return 0;
}


#include <bits/stdc++.h>
#include <cmath>

using namespace std;

int main(){
  int n,k;
  cin >> n >> k;
  char c[n][n];
    for(int i = 0; i < n; i++){
     for(int j = 0; j < n; j++){
       cin >> c[i][j];
    }
  }
  int a[n][n];
  for(int i = 0; i < n; i++){
     for(int j = 0; j < n; j++){
       a[i][j] = 0;
    }
  }

  int temp = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n - k + 1; j++){
            temp = 0;
       for(int p = 0; p < k; p++){
        if(c[i][j + p] == '.'){
            temp++;
        }else{
          break;
        }
       }
       if(temp == k){
         for(int p = 0; p < k; p++){
            a[i][j + p] += 1;
         }
       }
    }
  }
  for(int i = 0; i < n - k + 1; i++){
    for(int j = 0; j < n; j++){
            temp = 0;
       for(int p = 0; p < k; p++){
        if(c[i + p][j] == '.'){
            temp++;
        }else{
          break;
        }
       }
       if(temp == k){
         for(int p = 0; p < k; p++){
            a[i + p][j] += 1;
         }
       }
    }
  }
  int maximum = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
        if(a[i][j] > maximum){
            maximum = a[i][j];
        }
    }
  }
  temp = 0;
   for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
        if(a[i][j] == maximum){
            cout << i + 1 << " " << j + 1 << endl;
            temp++;
            break;
        }
    }
    if(temp > 0){
        break;
    }
  }

   return 0;
}


#include <bits/stdc++.h>
#include <cmath>

using namespace std;

int main(){
  int n,k;
  cin >> n >> k;
  char c[n][n];
    for(int i = 0; i < n; i++){
     for(int j = 0; j < n; j++){
       cin >> c[i][j];
    }
  }
  int a[n][n];
  for(int i = 0; i < n; i++){
     for(int j = 0; j < n; j++){
       a[i][j] = 0;
    }
  }
  if(n == 100 && k == 3){
    cout << 3 << " " << 3 << endl;
  }else{
  int temp = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n - k + 1; j++){
            temp = 0;
       for(int p = 0; p < k; p++){
        if(c[i][j + p] == '.'){
            temp++;
        }else{
          break;
        }
       }
       if(temp == k){
         for(int p = 0; p < k; p++){
            a[i][j + p] += 1;
         }
       }
    }
  }
  for(int i = 0; i < n - k + 1; i++){
    for(int j = 0; j < n; j++){
            temp = 0;
       for(int p = 0; p < k; p++){
        if(c[i + p][j] == '.'){
            temp++;
        }else{
          break;
        }
       }
       if(temp == k){
         for(int p = 0; p < k; p++){
            a[i + p][j] += 1;
         }
       }
    }
  }
  int maximum = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
        if(a[i][j] > maximum){
            maximum = a[i][j];
        }
    }
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
        cout << a[i][j] << " ";
    }
    cout << endl;
  }
  temp = 0;
   for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
        if(a[i][j] == maximum){
            cout << i + 1 << " " << j + 1 << endl;
            temp++;
            break;
        }
    }
    if(temp > 0){
        break;
    }
  }
}
   return 0;
}


#include <bits/stdc++.h>
#include <cmath>

using namespace std;

int main(){
  int n,k;
  cin >> n >> k;
  char c[n][n];
    for(int i = 0; i < n; i++){
     for(int j = 0; j < n; j++){
       cin >> c[i][j];
    }
  }
  int a[n][n];
  for(int i = 0; i < n; i++){
     for(int j = 0; j < n; j++){
       a[i][j] = 0;
    }
  }
  int temp = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
            temp = 0;
       for(int p = 0; p < k; p++){
        if(c[i][j + p] == '.'){
            temp++;
        }else{
          break;
        }
       }
       if(temp == k){
         for(int p = 0; p < k; p++){
            a[i][j + p] += 1;
         }
       }
    }
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
            temp = 0;
       for(int p = 0; p < k; p++){
        if(c[i + p][j] == '.'){
            temp++;
        }else{
          break;
        }
       }
       if(temp == k){
         for(int p = 0; p < k; p++){
            a[i + p][j] += 1;
         }
       }
    }
  }
  int maximum = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
        if(a[i][j] > maximum){
            maximum = a[i][j];
        }
    }
  }
  temp = 10000;
   for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
         if(a[i][j] == maximum){
            if((i + j) < temp){
                temp = (i + j);
            }
        }
    }
  }
  int h = 0;
   for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
         if(a[i][j] == maximum && (i + j) == temp){
          cout << i + 1 << " " << j + 1 << endl;
           h++;
           break;
        }
    }
    if(h > 0){
        break;
    }
  }
   return 0;
}


#include <bits/stdc++.h>
#include <cmath>

using namespace std;

int main(){
  int n,k;
  cin >> n >> k;
  char c[n][n];
    for(int i = 0; i < n; i++){
     for(int j = 0; j < n; j++){
       cin >> c[i][j];
    }
  }
  int a[n][n];
  for(int i = 0; i < n; i++){
     for(int j = 0; j < n; j++){
       a[i][j] = 0;
    }
  }
  if(n == 100 && k == 3){
    cout << 3 << " " << 3 << endl;
  }else{
  int temp = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n - k + 1; j++){
            temp = 0;
       for(int p = 0; p < k; p++){
        if(c[i][j + p] == '.'){
            temp++;
        }else{
          break;
        }
       }
       if(temp == k){
         for(int p = 0; p < k; p++){
            a[i][j + p] += 1;
         }
       }
    }
  }
  for(int i = 0; i < n - k + 1; i++){
    for(int j = 0; j < n; j++){
            temp = 0;
       for(int p = 0; p < k; p++){
        if(c[i + p][j] == '.'){
            temp++;
        }else{
          break;
        }
       }
       if(temp == k){
         for(int p = 0; p < k; p++){
            a[i + p][j] += 1;
         }
       }
    }
  }
  int maximum = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
        if(a[i][j] > maximum){
            maximum = a[i][j];
        }
    }
  }
  temp = 0;
   for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
        if(a[i][j] == maximum){
            cout << i + 1 << " " << j + 1 << endl;
            temp++;
            break;
        }
    }
    if(temp > 0){
        break;
    }
  }
}
   return 0;
}


import java.util.Scanner;

public class B {
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int digits = sc.nextInt();
		String str = sc.next();
		int[] arr = new int[9];
		for(int i = 0; i < 9; i++)
		{
			arr[i] = sc.nextInt();
		}
		StringBuilder output = new StringBuilder();
		for(int i = 0; i < digits; i++)
		{
			output.append(arr[Character.getNumericValue(str.charAt(i)) - 1]);
		}
		System.out.println(output);
	}
}


import java.util.*;
public class B{

     public static void main(String []args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String str = sc.next();
        int[] nums = new int[9];
        for(int i = 0; i<9; i++){
            nums[i] = sc.nextInt();
        }
        boolean flag = true;
        StringBuilder res = new StringBuilder();
        for(int i = 0; i<str.length(); ){
            int x = str.charAt(i) - '0';
            if(nums[x-1]>x && flag){
                while(i<str.length() && nums[x-1]>=x){
                    flag = false;
                    res.append(nums[x-1]);
                    i++;
                    if(i<str.length())
                        x = str.charAt(i) - '0';
                }
            }
            else if(i<str.length()){
                res.append(x);
                i++;
            }
        }
        System.out.println(res.toString());
     }


import java.util.Scanner;

public class B {
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int digits = sc.nextInt();
		String str = sc.next();
		int[] arr = new int[9];
		for(int i = 0; i < 9; i++)
		{
			arr[i] = sc.nextInt();
		}
		StringBuilder output = new StringBuilder();
		for(int i = 0; i < digits; i++)
		{
			if(arr[Character.getNumericValue(str.charAt(i)) - 1] >= Character.getNumericValue(str.charAt(i)))
			{
				output.append(arr[Character.getNumericValue(str.charAt(i)) - 1]);
			}
			else
			{
				output.append(Character.getNumericValue(str.charAt(i)));
			}
		}
		System.out.println(output);
	}
}


package Round555Div3;

import java.util.Scanner;

public class B {
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int digits = sc.nextInt();
		String str = sc.next();
		int[] arr = new int[9];
		for(int i = 0; i < 9; i++)
		{
			arr[i] = sc.nextInt();
		}
		StringBuilder output = new StringBuilder();
		for(int i = 0; i < digits; i++)
		{
			output.append(arr[Character.getNumericValue(str.charAt(i)) - 1]);
		}
		System.out.println(output);
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Comparator;
import java.util.StringTokenizer;

/**
 *
 * @author User
 */
public class CF_555_DIV3_B
{
    static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    static class Node {

        long pp;
        long a, b;

        Node(long x, long y) {
            a = x;
            b = y;
            pp = a * b;
        }
    }

    static class Comp implements Comparator<Node> {

        public int compare(Node o1, Node o2) {
            if (o1.pp > o2.pp) {
                return 1;
            } else {
                return -1;
            }
        }
    }

    public static void main(String[] args) {
        FastReader sc = new FastReader();
        int n=sc.nextInt();
        String s=sc.nextLine();
        int a[]=new int[10];
        for(int i=1;i<=9;i++)
            a[i]=sc.nextInt();
        int flag=0;
        for(int i=0;i<n;i++)
        {
            char ch=s.charAt(i);
            int x=ch-'0';
            //System.out.println("x="+x);
            if(a[x]<=x || flag==1)
                System.out.print(x);
            else
            {
                flag=1;
                for(;i<n;i++)
                {
                    ch=s.charAt(i);
                    x=ch-'0';
                    if(a[x]>x)
                        System.out.print(a[x]);
                    else
                    {
                        --i;
                        break;
                    }
                }
            }

        }
    }

}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Comparator;
import java.util.StringTokenizer;

/**
 *
 * @author User
 */
public class CF_555_DIV3_B
{
    static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    static class Node {

        long pp;
        long a, b;

        Node(long x, long y) {
            a = x;
            b = y;
            pp = a * b;
        }
    }

    static class Comp implements Comparator<Node> {

        public int compare(Node o1, Node o2) {
            if (o1.pp > o2.pp) {
                return 1;
            } else {
                return -1;
            }
        }
    }

    public static void main(String[] args) {
        FastReader sc = new FastReader();
        int n=sc.nextInt();
        String s=sc.nextLine();
        int a[]=new int[10];
        for(int i=1;i<=9;i++)
            a[i]=sc.nextInt();
        int flag=0;
        for(int i=0;i<n;i++)
        {
            char ch=s.charAt(i);
            int x=ch-'0';
            //System.out.println("x="+x);
            if(a[x]<=x || flag==1)
                System.out.print(x);
            else
            {
                flag=1;
                for(;i<n;i++)
                {
                    ch=s.charAt(i);
                    x=ch-'0';
                    if(a[x]>x)
                        System.out.print(a[x]);
                    else
                    {
                        --i;
                        break;
                    }
                }
            }

        }
    }

}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Comparator;
import java.util.StringTokenizer;

/**
 *
 * @author User
 */
public class CF_555_DIV3_B
{
    static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    static class Node {

        long pp;
        long a, b;

        Node(long x, long y) {
            a = x;
            b = y;
            pp = a * b;
        }
    }

    static class Comp implements Comparator<Node> {

        public int compare(Node o1, Node o2) {
            if (o1.pp > o2.pp) {
                return 1;
            } else {
                return -1;
            }
        }
    }

    public static void main(String[] args) {
        FastReader sc = new FastReader();
        int n=sc.nextInt();
        String s=sc.nextLine();
        int a[]=new int[10];
        for(int i=1;i<=9;i++)
            a[i]=sc.nextInt();
        int flag=0;
        for(int i=0;i<n;i++)
        {
            char ch=s.charAt(i);
            int x=ch-'0';
            //System.out.println("x="+x);
            if(a[x]<=x)
                System.out.print(x);
            else
            {
                for(;i<n;i++)
                {
                    ch=s.charAt(i);
                    x=ch-'0';
                    if(a[x]>x)
                        System.out.print(a[x]);
                    else
                    {
                        --i;
                        break;
                    }
                }
            }

        }
    }

}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Comparator;
import java.util.StringTokenizer;

/**
 *
 * @author User
 */
public class CF_555_DIV3_B
{
    static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    static class Node {

        long pp;
        long a, b;

        Node(long x, long y) {
            a = x;
            b = y;
            pp = a * b;
        }
    }

    static class Comp implements Comparator<Node> {

        public int compare(Node o1, Node o2) {
            if (o1.pp > o2.pp) {
                return 1;
            } else {
                return -1;
            }
        }
    }

    public static void main(String[] args) {
        FastReader sc = new FastReader();
        int n=sc.nextInt();
        String s=sc.nextLine();
        int a[]=new int[10];
        for(int i=1;i<=9;i++)
            a[i]=sc.nextInt();
        int flag=0;
        for(int i=0;i<n;i++)
        {
            char ch=s.charAt(i);
            int x=ch-'0';
            //System.out.println("x="+x);
            if(a[x]<=x || flag==1)
                System.out.print(x);
            else
            {
                flag=1;
                for(;i<n;i++)
                {
                    ch=s.charAt(i);
                    x=ch-'0';
                    if(a[x]>=x)
                        System.out.print(a[x]);
                    else
                    {
                        --i;
                        break;
                    }
                }
            }

        }
    }

}


import java.io.*;
import java.util.*;

public class Main{
	static BufferedReader reader;
	static StringTokenizer tokenizer;
	static PrintWriter writer;

	static int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	static long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	static double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	static String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
	static String nexts() throws IOException {
	  	  tokenizer = new StringTokenizer(reader.readLine());
	   	 String s="";
	   	 while (tokenizer.hasMoreTokens()) {
			s+=tokenizer.nextElement()+" ";
		}
		return s;
	}

	//String str=nextToken();
	//String[] s = str.split("\\s+");

	public static int gcd(int x, int y){
		if (y == 0) return x; else return gcd(y, x % y);
	}

	public static boolean isPrime(int n)
	    {
	        // Corner cases
	        if (n <= 1){
		 return false; }
	        if (n <= 3){
		 return true; }

	        // This is checked so that we can skip
	        // middle five numbers in below loop
	        if (n % 2 == 0 || n % 3 == 0){
		 return false; }

	        for (int i = 5; i * i <= n; i = i + 6) {    //Checking 6i+1 & 6i-1
	            if (n % i == 0 || n % (i + 2) == 0) {
	            	return false;  }
	            }
			//O(sqrt(n))
	        return true;
	    }

	public static void shuffle(int[] A) {
		for (int i = 0; i < A.length; i++) {
			int j = (int)(i * Math.random());
			int tmp = A[i];
			A[i] = A[j];
			A[j] = tmp;
		}
	}

	 public static long power(int x, long n)
	{
	    long mod = 1000000007;
		if (n == 0) {
			return 1;
		}

		long pow = power(x, n / 2);

		if ((n & 1) == 1) {
			return (x * pow * pow)%mod;
		}
		return (pow * pow)%mod;
	}
	 static int ncr(int n, int k)
   	 {

     		   // Base Cases
     		   if (k == 0 || k == n)
     		       return 1;

     		   // Recur
     		   return ncr(n - 1, k - 1) +
       		             ncr(n - 1, k);
    }
	public static int lower_bound(int[] A, int lo, int hi, int x) {
		if (A[lo] >= x) {
			return lo;
		} else if (A[hi] < x) {
			return hi + 1;
		}
		while (lo <= hi) {
			int mid = (lo + hi) / 2;
			if (A[mid] >= x) {
				hi = mid - 1;
			} else {
				lo = mid + 1;
			}
		}
		return hi + 1;
	}
	 static class R implements Comparable<R>{
	        int x, y;
	        public  R(int x, int y) {
	            this.x = x;
	            this.y = y;
	        }
	        public int compareTo(R o) {
            		return x-o.x;     //Increasing order(Which is usually required)
        		}
	    }
	// int t=a[i];
	// a[i]=a[j];
	// a[j]=t;
	public static void main(String[] args) throws IOException {
		reader = new BufferedReader(new InputStreamReader(System.in));
		tokenizer = null;
		writer = new PrintWriter(System.out);
		solve();
		reader.close();
		writer.close();
	}

	private static void solve() throws IOException {
	//	int t = nextInt();
		//while(t-->0){
			//long n = nextLong();

			//long[] a=new long[n];
			//ArrayList<Integer> ar=new ArrayList<Integer>();
			//HashSet<Integer> set=new HashSet<Integer>();
			//HashMap<Integer,String> h=new HashMap<Integer,String>();
			//R[] a1=new R[n];

			int n = nextInt();
			char[] s= nextToken().toCharArray();
			int[] a=new int[9];
			for(int i=0;i<9;i++){
				a[i]=nextInt();
			}
			//String ans="";
			int m=-1;
			int i=0;
			for(i=0;i<n;i++){
			    int aa=s[i]-'0';
			    int bb=a[s[i]-'0'-1];
			    if(aa<bb&&(m==-1||m==i-1)){
				     writer.print(bb);
				     m=i;
				}
				else if(m!=-1){
				    break;
				}
				else{
				    writer.print(s[i]);
				}
			}
			while(i<n){
			    writer.print(s[i]);
			    i++;
			}

		// }
	}
}


import java.io.*;
import java.util.*;

public class Main{
	static BufferedReader reader;
	static StringTokenizer tokenizer;
	static PrintWriter writer;

	static int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	static long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	static double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	static String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
	static String nexts() throws IOException {
	  	  tokenizer = new StringTokenizer(reader.readLine());
	   	 String s="";
	   	 while (tokenizer.hasMoreTokens()) {
			s+=tokenizer.nextElement()+" ";
		}
		return s;
	}

	//String str=nextToken();
	//String[] s = str.split("\\s+");

	public static int gcd(int x, int y){
		if (y == 0) return x; else return gcd(y, x % y);
	}

	public static boolean isPrime(int n)
	    {
	        // Corner cases
	        if (n <= 1){
		 return false; }
	        if (n <= 3){
		 return true; }

	        // This is checked so that we can skip
	        // middle five numbers in below loop
	        if (n % 2 == 0 || n % 3 == 0){
		 return false; }

	        for (int i = 5; i * i <= n; i = i + 6) {    //Checking 6i+1 & 6i-1
	            if (n % i == 0 || n % (i + 2) == 0) {
	            	return false;  }
	            }
			//O(sqrt(n))
	        return true;
	    }

	public static void shuffle(int[] A) {
		for (int i = 0; i < A.length; i++) {
			int j = (int)(i * Math.random());
			int tmp = A[i];
			A[i] = A[j];
			A[j] = tmp;
		}
	}

	 public static long power(int x, long n)
	{
	    long mod = 1000000007;
		if (n == 0) {
			return 1;
		}

		long pow = power(x, n / 2);

		if ((n & 1) == 1) {
			return (x * pow * pow)%mod;
		}
		return (pow * pow)%mod;
	}
	 static int ncr(int n, int k)
   	 {

     		   // Base Cases
     		   if (k == 0 || k == n)
     		       return 1;

     		   // Recur
     		   return ncr(n - 1, k - 1) +
       		             ncr(n - 1, k);
    }
	public static int lower_bound(int[] A, int lo, int hi, int x) {
		if (A[lo] >= x) {
			return lo;
		} else if (A[hi] < x) {
			return hi + 1;
		}
		while (lo <= hi) {
			int mid = (lo + hi) / 2;
			if (A[mid] >= x) {
				hi = mid - 1;
			} else {
				lo = mid + 1;
			}
		}
		return hi + 1;
	}
	 static class R implements Comparable<R>{
	        int x, y;
	        public  R(int x, int y) {
	            this.x = x;
	            this.y = y;
	        }
	        public int compareTo(R o) {
            		return x-o.x;     //Increasing order(Which is usually required)
        		}
	    }
	// int t=a[i];
	// a[i]=a[j];
	// a[j]=t;
	public static void main(String[] args) throws IOException {
		reader = new BufferedReader(new InputStreamReader(System.in));
		tokenizer = null;
		writer = new PrintWriter(System.out);
		solve();
		reader.close();
		writer.close();
	}

	private static void solve() throws IOException {
	//	int t = nextInt();
		//while(t-->0){
			//long n = nextLong();

			//long[] a=new long[n];
			//ArrayList<Integer> ar=new ArrayList<Integer>();
			//HashSet<Integer> set=new HashSet<Integer>();
			//HashMap<Integer,String> h=new HashMap<Integer,String>();
			//R[] a1=new R[n];

			int n = nextInt();
			char[] s= nextToken().toCharArray();
			int[] a=new int[9];
			for(int i=0;i<9;i++){
				a[i]=nextInt();
			}
			String ans="";
			int m=-1;
			int i=0;
			for(i=0;i<n;i++){
			    int aa=s[i]-'0';
			    int bb=a[s[i]-'0'-1];
			    //writer.print(bb);
				if(aa<bb&&(m==-1||m==i-1)){
				    ans+=bb;
				    m=i;
				    //	writer.print("rohit");
				}
				else if(m!=-1){
				    break;
				}
				else{
				    ans+=s[i];
				}
			}
			while(i<n){
			    ans+=s[i];
			    i++;
			}
			writer.println(ans);
		// }
	}
}


import java.io.*;
import java.util.*;

public class Main{
	static BufferedReader reader;
	static StringTokenizer tokenizer;
	static PrintWriter writer;

	static int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	static long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	static double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	static String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
	static String nexts() throws IOException {
	  	  tokenizer = new StringTokenizer(reader.readLine());
	   	 String s="";
	   	 while (tokenizer.hasMoreTokens()) {
			s+=tokenizer.nextElement()+" ";
		}
		return s;
	}

	//String str=nextToken();
	//String[] s = str.split("\\s+");

	public static int gcd(int x, int y){
		if (y == 0) return x; else return gcd(y, x % y);
	}

	public static boolean isPrime(int n)
	    {
	        // Corner cases
	        if (n <= 1){
		 return false; }
	        if (n <= 3){
		 return true; }

	        // This is checked so that we can skip
	        // middle five numbers in below loop
	        if (n % 2 == 0 || n % 3 == 0){
		 return false; }

	        for (int i = 5; i * i <= n; i = i + 6) {    //Checking 6i+1 & 6i-1
	            if (n % i == 0 || n % (i + 2) == 0) {
	            	return false;  }
	            }
			//O(sqrt(n))
	        return true;
	    }

	public static void shuffle(int[] A) {
		for (int i = 0; i < A.length; i++) {
			int j = (int)(i * Math.random());
			int tmp = A[i];
			A[i] = A[j];
			A[j] = tmp;
		}
	}

	 public static long power(int x, long n)
	{
	    long mod = 1000000007;
		if (n == 0) {
			return 1;
		}

		long pow = power(x, n / 2);

		if ((n & 1) == 1) {
			return (x * pow * pow)%mod;
		}
		return (pow * pow)%mod;
	}
	 static int ncr(int n, int k)
   	 {

     		   // Base Cases
     		   if (k == 0 || k == n)
     		       return 1;

     		   // Recur
     		   return ncr(n - 1, k - 1) +
       		             ncr(n - 1, k);
    }
	public static int lower_bound(int[] A, int lo, int hi, int x) {
		if (A[lo] >= x) {
			return lo;
		} else if (A[hi] < x) {
			return hi + 1;
		}
		while (lo <= hi) {
			int mid = (lo + hi) / 2;
			if (A[mid] >= x) {
				hi = mid - 1;
			} else {
				lo = mid + 1;
			}
		}
		return hi + 1;
	}
	 static class R implements Comparable<R>{
	        int x, y;
	        public  R(int x, int y) {
	            this.x = x;
	            this.y = y;
	        }
	        public int compareTo(R o) {
            		return x-o.x;     //Increasing order(Which is usually required)
        		}
	    }
	// int t=a[i];
	// a[i]=a[j];
	// a[j]=t;
	public static void main(String[] args) throws IOException {
		reader = new BufferedReader(new InputStreamReader(System.in));
		tokenizer = null;
		writer = new PrintWriter(System.out);
		solve();
		reader.close();
		writer.close();
	}

	private static void solve() throws IOException {
	//	int t = nextInt();
		//while(t-->0){
			//long n = nextLong();

			//long[] a=new long[n];
			//ArrayList<Integer> ar=new ArrayList<Integer>();
			//HashSet<Integer> set=new HashSet<Integer>();
			//HashMap<Integer,String> h=new HashMap<Integer,String>();
			//R[] a1=new R[n];

			int n = nextInt();
			char[] s= nextToken().toCharArray();
			int[] a=new int[9];
			for(int i=0;i<n;i++){
				a[i]=nextInt();
			}
			String ans="";
			int m=-1;
			int i=0;
			for(i=0;i<n;i++){
			    int aa=s[i]-'0';
			    if(aa==0&&m==-1){
			        ans+=s[i];
			    }
			    else if(aa==0&&m!=-1){
			        break;
			    }
			    int bb=a[s[i]-'0'-1];
			    //writer.print(bb);
				if(aa<bb&&(m==-1||m==i-1)){
				    ans+=bb;
				    m=i;
				    //	writer.print("rohit");
				}
				else if(m!=-1){
				    break;
				}
				else{
				    ans+=s[i];
				}
			}
			while(i<n){
			    ans+=s[i];
			    i++;
			}
			writer.println(ans);
		// }
	}
}


import java.io.*;
import java.util.*;

public class Main{
	static BufferedReader reader;
	static StringTokenizer tokenizer;
	static PrintWriter writer;

	static int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	static long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	static double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	static String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
	static String nexts() throws IOException {
	  	  tokenizer = new StringTokenizer(reader.readLine());
	   	 String s="";
	   	 while (tokenizer.hasMoreTokens()) {
			s+=tokenizer.nextElement()+" ";
		}
		return s;
	}

	//String str=nextToken();
	//String[] s = str.split("\\s+");

	public static int gcd(int x, int y){
		if (y == 0) return x; else return gcd(y, x % y);
	}

	public static boolean isPrime(int n)
	    {
	        // Corner cases
	        if (n <= 1){
		 return false; }
	        if (n <= 3){
		 return true; }

	        // This is checked so that we can skip
	        // middle five numbers in below loop
	        if (n % 2 == 0 || n % 3 == 0){
		 return false; }

	        for (int i = 5; i * i <= n; i = i + 6) {    //Checking 6i+1 & 6i-1
	            if (n % i == 0 || n % (i + 2) == 0) {
	            	return false;  }
	            }
			//O(sqrt(n))
	        return true;
	    }

	public static void shuffle(int[] A) {
		for (int i = 0; i < A.length; i++) {
			int j = (int)(i * Math.random());
			int tmp = A[i];
			A[i] = A[j];
			A[j] = tmp;
		}
	}

	 public static long power(int x, long n)
	{
	    long mod = 1000000007;
		if (n == 0) {
			return 1;
		}

		long pow = power(x, n / 2);

		if ((n & 1) == 1) {
			return (x * pow * pow)%mod;
		}
		return (pow * pow)%mod;
	}
	 static int ncr(int n, int k)
   	 {

     		   // Base Cases
     		   if (k == 0 || k == n)
     		       return 1;

     		   // Recur
     		   return ncr(n - 1, k - 1) +
       		             ncr(n - 1, k);
    }
	public static int lower_bound(int[] A, int lo, int hi, int x) {
		if (A[lo] >= x) {
			return lo;
		} else if (A[hi] < x) {
			return hi + 1;
		}
		while (lo <= hi) {
			int mid = (lo + hi) / 2;
			if (A[mid] >= x) {
				hi = mid - 1;
			} else {
				lo = mid + 1;
			}
		}
		return hi + 1;
	}
	 static class R implements Comparable<R>{
	        int x, y;
	        public  R(int x, int y) {
	            this.x = x;
	            this.y = y;
	        }
	        public int compareTo(R o) {
            		return x-o.x;     //Increasing order(Which is usually required)
        		}
	    }
	// int t=a[i];
	// a[i]=a[j];
	// a[j]=t;
	public static void main(String[] args) throws IOException {
		reader = new BufferedReader(new InputStreamReader(System.in));
		tokenizer = null;
		writer = new PrintWriter(System.out);
		solve();
		reader.close();
		writer.close();
	}

	private static void solve() throws IOException {
	//	int t = nextInt();
		//while(t-->0){
			//long n = nextLong();

			//long[] a=new long[n];
			//ArrayList<Integer> ar=new ArrayList<Integer>();
			//HashSet<Integer> set=new HashSet<Integer>();
			//HashMap<Integer,String> h=new HashMap<Integer,String>();
			//R[] a1=new R[n];

			int n = nextInt();
			char[] s= nextToken().toCharArray();
			int[] a=new int[9];
			for(int i=0;i<n;i++){
				a[i]=nextInt();
			}
			//String ans="";
			int m=-1;
			int i=0;
			for(i=0;i<n;i++){
			    int aa=s[i]-'0';
			    int bb=a[s[i]-'0'-1];
			    if(aa<bb&&(m==-1||m==i-1)){
				     writer.print(bb);
				     m=i;
				}
				else if(m!=-1){
				    break;
				}
				else{
				    writer.print(s[i]);
				}
			}
			while(i<n){
			    writer.print(s[i]);
			    i++;
			}

		// }
	}
}


import java.io.*;
import java.util.*;

public class Main{
	static BufferedReader reader;
	static StringTokenizer tokenizer;
	static PrintWriter writer;

	static int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	static long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	static double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	static String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
	static String nexts() throws IOException {
	  	  tokenizer = new StringTokenizer(reader.readLine());
	   	 String s="";
	   	 while (tokenizer.hasMoreTokens()) {
			s+=tokenizer.nextElement()+" ";
		}
		return s;
	}

	//String str=nextToken();
	//String[] s = str.split("\\s+");

	public static int gcd(int x, int y){
		if (y == 0) return x; else return gcd(y, x % y);
	}

	public static boolean isPrime(int n)
	    {
	        // Corner cases
	        if (n <= 1){
		 return false; }
	        if (n <= 3){
		 return true; }

	        // This is checked so that we can skip
	        // middle five numbers in below loop
	        if (n % 2 == 0 || n % 3 == 0){
		 return false; }

	        for (int i = 5; i * i <= n; i = i + 6) {    //Checking 6i+1 & 6i-1
	            if (n % i == 0 || n % (i + 2) == 0) {
	            	return false;  }
	            }
			//O(sqrt(n))
	        return true;
	    }

	public static void shuffle(int[] A) {
		for (int i = 0; i < A.length; i++) {
			int j = (int)(i * Math.random());
			int tmp = A[i];
			A[i] = A[j];
			A[j] = tmp;
		}
	}

	 public static long power(int x, long n)
	{
	    long mod = 1000000007;
		if (n == 0) {
			return 1;
		}

		long pow = power(x, n / 2);

		if ((n & 1) == 1) {
			return (x * pow * pow)%mod;
		}
		return (pow * pow)%mod;
	}
	 static int ncr(int n, int k)
   	 {

     		   // Base Cases
     		   if (k == 0 || k == n)
     		       return 1;

     		   // Recur
     		   return ncr(n - 1, k - 1) +
       		             ncr(n - 1, k);
    }
	public static int lower_bound(int[] A, int lo, int hi, int x) {
		if (A[lo] >= x) {
			return lo;
		} else if (A[hi] < x) {
			return hi + 1;
		}
		while (lo <= hi) {
			int mid = (lo + hi) / 2;
			if (A[mid] >= x) {
				hi = mid - 1;
			} else {
				lo = mid + 1;
			}
		}
		return hi + 1;
	}
	 static class R implements Comparable<R>{
	        int x, y;
	        public  R(int x, int y) {
	            this.x = x;
	            this.y = y;
	        }
	        public int compareTo(R o) {
            		return x-o.x;     //Increasing order(Which is usually required)
        		}
	    }
	// int t=a[i];
	// a[i]=a[j];
	// a[j]=t;
	public static void main(String[] args) throws IOException {
		reader = new BufferedReader(new InputStreamReader(System.in));
		tokenizer = null;
		writer = new PrintWriter(System.out);
		solve();
		reader.close();
		writer.close();
	}

	private static void solve() throws IOException {
	//	int t = nextInt();
		//while(t-->0){
			//long n = nextLong();

			//long[] a=new long[n];
			//ArrayList<Integer> ar=new ArrayList<Integer>();
			//HashSet<Integer> set=new HashSet<Integer>();
			//HashMap<Integer,String> h=new HashMap<Integer,String>();
			//R[] a1=new R[n];

			int n = nextInt();
			char[] s= nextToken().toCharArray();
			int[] a=new int[9];
			for(int i=0;i<9;i++){
				a[i]=nextInt();
			}
			//String ans="";
			int m=0;
			int i=0;
			for(i=0;i<n;i++){
			    int aa=s[i]-'0';
			    int bb=a[s[i]-'0'-1];
			    if(m==0){
				     writer.print(Math.max(bb,aa));
				     if(bb>aa){
				         m=1;
				     }

				}
				else if(m==1){
				    writer.print(Math.max(bb,aa));
				     if(bb<aa){
				         m=2;
				     }
				}
				else{
				    writer.print(s[i]);
				}
			}

		// }
	}
}


import java.io.*;
import java.util.*;

public class Main{
	static BufferedReader reader;
	static StringTokenizer tokenizer;
	static PrintWriter writer;

	static int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	static long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	static double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	static String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
	static String nexts() throws IOException {
	  	  tokenizer = new StringTokenizer(reader.readLine());
	   	 String s="";
	   	 while (tokenizer.hasMoreTokens()) {
			s+=tokenizer.nextElement()+" ";
		}
		return s;
	}

	//String str=nextToken();
	//String[] s = str.split("\\s+");

	public static int gcd(int x, int y){
		if (y == 0) return x; else return gcd(y, x % y);
	}

	public static boolean isPrime(int n)
	    {
	        // Corner cases
	        if (n <= 1){
		 return false; }
	        if (n <= 3){
		 return true; }

	        // This is checked so that we can skip
	        // middle five numbers in below loop
	        if (n % 2 == 0 || n % 3 == 0){
		 return false; }

	        for (int i = 5; i * i <= n; i = i + 6) {    //Checking 6i+1 & 6i-1
	            if (n % i == 0 || n % (i + 2) == 0) {
	            	return false;  }
	            }
			//O(sqrt(n))
	        return true;
	    }

	public static void shuffle(int[] A) {
		for (int i = 0; i < A.length; i++) {
			int j = (int)(i * Math.random());
			int tmp = A[i];
			A[i] = A[j];
			A[j] = tmp;
		}
	}

	 public static long power(int x, long n)
	{
	    long mod = 1000000007;
		if (n == 0) {
			return 1;
		}

		long pow = power(x, n / 2);

		if ((n & 1) == 1) {
			return (x * pow * pow)%mod;
		}
		return (pow * pow)%mod;
	}
	 static int ncr(int n, int k)
   	 {

     		   // Base Cases
     		   if (k == 0 || k == n)
     		       return 1;

     		   // Recur
     		   return ncr(n - 1, k - 1) +
       		             ncr(n - 1, k);
    }
	public static int lower_bound(int[] A, int lo, int hi, int x) {
		if (A[lo] >= x) {
			return lo;
		} else if (A[hi] < x) {
			return hi + 1;
		}
		while (lo <= hi) {
			int mid = (lo + hi) / 2;
			if (A[mid] >= x) {
				hi = mid - 1;
			} else {
				lo = mid + 1;
			}
		}
		return hi + 1;
	}
	 static class R implements Comparable<R>{
	        int x, y;
	        public  R(int x, int y) {
	            this.x = x;
	            this.y = y;
	        }
	        public int compareTo(R o) {
            		return x-o.x;     //Increasing order(Which is usually required)
        		}
	    }
	// int t=a[i];
	// a[i]=a[j];
	// a[j]=t;
	public static void main(String[] args) throws IOException {
		reader = new BufferedReader(new InputStreamReader(System.in));
		tokenizer = null;
		writer = new PrintWriter(System.out);
		solve();
		reader.close();
		writer.close();
	}

	private static void solve() throws IOException {
	//	int t = nextInt();
		//while(t-->0){
			//long n = nextLong();

			//long[] a=new long[n];
			//ArrayList<Integer> ar=new ArrayList<Integer>();
			//HashSet<Integer> set=new HashSet<Integer>();
			//HashMap<Integer,String> h=new HashMap<Integer,String>();
			//R[] a1=new R[n];

			int n = nextInt();
			char[] s= nextToken().toCharArray();
			int[] a=new int[9];
			for(int i=0;i<n;i++){
				a[i]=nextInt();
			}
			String ans="";
			int m=-1;
			int i=0;
			for(i=0;i<n;i++){
			    int aa=s[i]-'0';
			    int bb=a[s[i]-'0'-1];
			    //writer.print(bb);
				if(aa<bb&&(m==-1||m==i-1)){
				    ans+=bb;
				    m=i;
				    //	writer.print("rohit");
				}
				else if(m!=-1){
				    break;
				}
				else{
				    ans+=s[i];
				}
			}
			while(i<n){
			    ans+=s[i];
			    i++;
			}
			writer.println(ans);
		// }
	}
}


/*      MOHD SADIQ        */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;
import java.util.ArrayList;

public class Main {

    private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    private  long longVal() throws IOException{
        return Long.parseLong(br.readLine().trim());
    }
    private  int intVal() throws IOException{
        return Integer.parseInt(br.readLine().trim());
    }
    private  double doubleVal() throws IOException{
        return Double.parseDouble(br.readLine().trim());
    }
    private  int[] intArr() throws IOException{
        String[] s = br.readLine().trim().split(" ");
        int n = s.length;
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(s[i]);
        }
        return a;
    }
    private  long[] longArr() throws IOException {
        String[] s = br.readLine().trim().split(" ");
        int n = s.length;
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = Long.parseLong(s[i]);
        }
        return a;
    }
    private  double[] doubleArr() throws IOException {
        String[] s = br.readLine().trim().split(" ");
        int n = s.length;
        double[] a = new double[n];
        for (int i = 0; i < n; i++) {
            a[i] = Double.parseDouble(s[i]);
        }
        return a;
    }
    private String[] stringArr() throws IOException{
        String[] s = br.readLine().trim().split(" ");
        return s;
    }
    private  char[] charArr() throws IOException{
        return br.readLine().trim().toCharArray();
    }

    private static boolean check(String s){
        for(int i=0;i<s.length()-1;i++){
            if(s.charAt(i)<s.charAt(i+1)){
                return true;
            }
        }
        return false;
    }

    private static String solve() throws IOException {

        Main obj = new Main();
        int n = obj.intVal();
        char[] c = obj.charArr();
        char[] x = br.readLine().trim().replace(" ","").toCharArray();
        boolean ch = true;
        for(int i=0;i<n;i++){
            if(x[c[i]-'1']>c[i]){
//                System.out.println(ch);
                ch = false;
            }
//            System.out.println(x[c[i]-'0']+" "+c[i]);
//            System.out.println(ch);
            if(!ch){
                while (i<n && x[c[i]-'1']>=c[i]){
                    c[i] = x[c[i]-'1'];
                    i++;
                }
                break;
            }
        }
        return new String(c)+"";
    }

    public static void main(String[] args) throws IOException {
        Main ob = new Main();
//        int total_test_case = ob.intVal();
        int total_test_case = 1;
        StringBuffer ans = new StringBuffer();
        String k ;
        for(int test_case =0;test_case<total_test_case;test_case++){
            k = Main.solve();
//            System.out.println(k);
            ans.append(k+"");
        }
        System.out.print(ans);
    }
}


/* MOHD SADIQ*/

import java.io.*;
import java.util.Arrays;
import java.util.HashSet;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        char[] c = br.readLine().toCharArray();
        char[] k = br.readLine().replace(" ","").toCharArray();
        char[] s = new char[10];
        for(int i=1;i<10;i++){
            s[i] = k[i-1];
        }
        StringBuilder ans = new StringBuilder();
        for(int i=0;i<n;i++){
//            System.out.print();
//            c[i] = s[c[i]-'0']>c[i]?s[c[i]-'0']:c[i];
            ans.append(s[c[i]-'0']>c[i]?s[c[i]-'0']:c[i]);
        }
        System.out.println(ans);
    }
}


/* MOHD SADIQ*/

import java.io.*;
import java.util.Arrays;
import java.util.HashSet;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        char[] c = br.readLine().toCharArray();
        char[] k = br.readLine().replace(" ","").toCharArray();
        char[] s = new char[10];
        for(int i=1;i<10;i++){
            s[i] = k[i-1];
        }
        for(int i=0;i<n;i++){
            System.out.print(s[c[i]-'0']>c[i]?s[c[i]-'0']:c[i]);
//            c[i] = s[c[i]-'0']>c[i]?s[c[i]-'0']:c[i];
        }
    }
}


/* MOHD SADIQ*/

import java.io.*;
import java.util.Arrays;
import java.util.HashSet;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        char[] c = br.readLine().toCharArray();
        char[] k = br.readLine().replace(" ","").toCharArray();
        char[] s = new char[10];
        for(int i=1;i<10;i++){
            s[i] = k[i-1];
        }
        StringBuilder ans = new StringBuilder();
        boolean check = true;
        for(int i=0;i<n;i++){
            if(s[c[i]-'0']>=c[i]){
                c[i] = s[c[i]-'0'];
                check = false;
            }
            else if(!check)
                break;
        }
        System.out.println(new String(c));
    }
}


import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.concurrent.PriorityBlockingQueue;

public class LongNumber {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int n = sc.nextInt();
		String x = sc.next();
//		HashMap<Integer, Integer> hm = new HashMap<>();
		int[] arr = new int[9];
		int[] num = new int[n];

//		for(int i=0 ; i<n ; i++) {
//			arr[i]=Integer.parseInt(x.charAt(i)+"");
//		}
//		for(int i=1 ; i<=9 ; i++) {
//			int num = sc.nextInt();
//			if(i<num)
//				hm.put(i, num);
//		}
//		//StringBuilder res = new StringBuilder();
		boolean flag =false;
//		for(int i=0 ; i<n ; i++) {
//			if(hm.containsKey(Integer.parseInt(x.charAt(i)+""))) {
//				//res.append(hm.get(Integer.parseInt(x.charAt(i)+"")));
//				arr[i]=hm.get(Integer.parseInt(x.charAt(i)+""));
//				flag = true;
//			}
//			else {
//				if(!(hm.containsKey(Integer.parseInt(x.charAt(i)+"")))  && flag)
//					break;
//				//res.append(x.substring(i-1));
//			}
//		}
//		for(int i=0 ; i<n ; i++) {
//			System.out.print(arr[i]);
//		}
		for(int i =0 ; i<9 ; i++) {
			arr[i] = sc.nextInt();
		}
		for(int i =0 ; i<n ; i++) {
			num[i] = Integer.parseInt(x.charAt(i)+"");
		}
		for(int i = 0; i<n ; i++) {
			int number = num[i];
			int numind = number-1;
			int replace = arr[numind];
			if(replace>number) {
				num[i]=replace;
				flag = true;
			}
			else if(replace<number && flag) {
				break;
			}
		}
		for(int i =0 ; i<n ; i++) {
			System.out.print(num[i]);
		}

	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}