#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
signed main(){
  int x=0,y=0,z=0;
  string s;
  std::cin >> s>>x;
  rep(i,s.size()){
    if(i*x>s.size()-1)return 0;
    std::cout << s[i*x];
  }
}

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

int main(){
	int n,k;
	cin >> n >> k;
	int mask = 0;
	for(int i = 0; i < k; i ++) {
		int p;
		cin >> p;
		mask |= (1 << p);
	}

	for(int i = n; ; i ++) {
		int t = i, m = 0;
		while(t) m |= (1 << (t % 10)), t /= 10;
		if((mask & m) == 0) {
			cout << i << endl;
			break;
		}
	}

}
