#include<bits/stdc++.h>
#define ll long long 
#define hell 1000000007 
#define F first
#define re 15000000
#define S second
#define pb push_back
#define all(a)  (a).begin(),(a).end()
#define rep(i,a,b) for(ll int i = a;i<b;i++)
#define pi 3.1415926536
#define Mod 998244353
#define endl '\n'
  //char a[2000][2000];
  using namespace std;
  int sum (ll a)
  {
      int sum =0;
      while(a>0)
      {
          sum = sum + (a%10);
          a=a/10;
      }
      return sum;
  }
  int count_digit(ll n)
  {
     int  count =0;
      while(n>0)
      {
          n = n/10;
          count++;
          //count++;
      }
      return count;
  }
  int binarySearch(int x,int y ,ll z ,ll v[])
  {
      int low = x;
      int high = y;
      int mid = x+(y-x)/2;
      while(low<=high)
      {
          if(v[mid]==z)
              return mid;
          if(v[mid]<z)
              return binarySearch(mid+1,high,z,v);
          if(v[mid]>z)
              return binarySearch(low,mid-1,z,v);
      }
      return -1;
  }
  ll modularExponentiation(ll x,ll n,ll M)
  {
      if(n==0)
          return 1;
      else if(n%2 == 0)        //n is even
          return modularExponentiation((x*x)%M,n/2,M);
      else                             //n is odd
          return (x*modularExponentiation((x*x)%M,(n-1)/2,M))%M;
 
  } 
  ll binaryExponentiation(ll x,ll n)
  {
      if(n==0)
          return 1;
      else if(n%2 == 0)        //n is even
          return binaryExponentiation(x*x,n/2);
      else                             //n is odd
          return x*binaryExponentiation(x*x,(n-1)/2);
  }
 
 
 
 
  set<ll> s;
  //vector<ll> v;
  void genrate(ll n,int len,int max)
  {
      if(len>max)
          return ;
      s.insert(n);
      genrate(n*10+1,len+1,max);
      genrate(n*10+0,len+1,max);
  }
  bool visited[200005];
  vector<ll> v[200005];
  bool recur[200005];
  int c = 0;
  void dfs(int x ,int parent)
  {
     visited[x] = 1;
     if(v[x].size() != 2)
      c = -1;
     for(int i = 0;i<v[x].size();i++){
      if(v[x][i] == parent)
        continue;
      if(visited[v[x][i]] && v[x].size() == 2 && c ==  0)
          c = 1;
      else if(!visited[v[x][i]]){
       dfs(v[x][i],x);
     }
     //return false;
      }
  }
  //memset(level,0,sizeof(level));    
  /*void topological_sort(int x)
  {
      visited[x] = 1;
    //  sort(all(v[x]));
      for(int i =0;i<v[x].size();i++)
      {
          if(visited[v[x][i]]!=1){
              //level[v[x][i]] = level[x]+1;
              topological_sort(v[x][i]);
          }
      }
      ans.pb(x);
  }*/
  //char a2001][2001];
  ///**************** Cycle using DSU *********************///
// vector<int> v[200005];
vector<int> ans(200005,-1);
vector<int> a;
int n;
void bfs(vector<int> &S, vector<int> &E){
  vector<int> dis(n+1,-1);
  queue<int> Q;
  for(int i = 0;i<S.size();i++){
    dis[S[i]]  = 0;
    Q.push(S[i]);
    // cout<<a[S[i]]<<" ";
  }
  // cout<<endl;
  while(!Q.empty()){
    int x = Q.front();
    Q.pop();
    for(int j = 0;j<v[x].size();j++){
      if(dis[v[x][j]] == -1){
        dis[v[x][j]] = dis[x]+1;
        Q.push(v[x][j]);
      }
    }
  }
  for(int i = 0;i<E.size();i++){
    ans[E[i]] = dis[E[i]];
  }
  return ;
}

int main()
  {   
      ios_base::sync_with_stdio(false);
      cin.tie(0);
      cout.tie(0);            
      //std::setprecision(20);      
      int tests=1;
        //freopen("input.txt", "r", stdin);
       // cin>>tests;
        
     while(tests--) 
      {
        int n,k;
        cin>>n>>k;
        map<int,int> m;
        for(int i = 0;i<k;i++){
          int x;
          cin>>x;
          m[x] = 1;
        }
        for(int i = n;i<=100000;i++){
          int x = i;
          int f = 1;
          while(x){
            if(m.find(x%10)!=m.end()){
              f = 0;
              break;
            }
            x = x/10;
          }
          if(f){
            cout<<i;
            exit(0);    
          }
        }
      }
}




Measured memory_bytes: 5760