// Original C++ solution (slower):
#include <bits/stdc++.h>

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)

#define rep(i,n) for (int i = (0); i < (n); ++i)

#define rng(x) (x).begin(),(x).end()

#define rrng(x) (x).rbegin(),(x).rend()

#define show(x) cout << #x << " = " << (x) << endl;

#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl;

#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl;

#define fi first

#define se second

#define pb push_back

#define eb emplace_back

#define sz(x) (int)(x).size()

#define bn(x) ((1<<x)-1)

#define dup(x,y) (((x)+(y)-1)/(y))

#define uni(x) x.erase(unique(rng(x)),x.end())

#define SP << " " <<

using namespace std;

using ll = long long;

using vi = vector<int>;

using vvi = vector<vi>;

using vll = vector<ll>;

using pii = pair<int, int>;

using tiii = tuple<int, int, int>;

const int mod = 1000000007;

const double EPS = 1e-9;

const int INF = 1<<30;

const ll INFLL = 1LL<<60;

//cout << fixed << setprecision(10);



template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }



int main () {

  int n, k;

  cin >> n >> k;

  vi d(k);

  rep(i,k) cin >> d[i];



  for (int i = n; i <= 10*n; ++i) {

    string s = to_string(i);

    bool ok = true;

    rep(j,sz(s)) {

      if (binary_search(rng(d), s[j]-'0')) {

        ok = false;

        break;

      }

    }

    if (ok) {

      cout << i << endl;

      return 0;

    }

  }

  return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)

#define rep(i,n) for (int i = (0); i < (n); ++i)

#define rng(x) (x).begin(),(x).end()

#define rrng(x) (x).rbegin(),(x).rend()

#define show(x) cout << #x << " = " << (x) << endl;

#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl;

#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl;

#define fi first

#define se second

#define pb push_back

#define eb emplace_back

#define sz(x) (int)(x).size()

#define bn(x) ((1<<x)-1)

#define dup(x,y) (((x)+(y)-1)/(y))

#define uni(x) x.erase(unique(rng(x)),x.end())

#define SP << " " <<

using namespace std;

using ll = long long;

using vi = vector<int>;

using vvi = vector<vi>;

using vll = vector<ll>;

using pii = pair<int, int>;

using tiii = tuple<int, int, int>;

const int mod = 1000000007;

const double EPS = 1e-9;

const int INF = 1<<30;

const ll INFLL = 1LL<<60;

//cout << fixed << setprecision(10);



template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }



int main () {

  int n, k;

  cin >> n >> k;

  vi d(k);

  rep(i,k) cin >> d[i];



  for (int i = n; i <= 10*n; ++i) {

    int tmp = i;

    bool ok = true;

    while (tmp > 0) {

      if (binary_search(rng(d),tmp%10)) {

        ok = false;

        break;

      }

      tmp /= 10;

    }

    if (ok) {

      cout << i << endl;

      return 0;

    }

  }

  return 0;

}

// Fastest known solution for this problem: