'use strict';
let lines = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n');
lines.pop();
let n = parseInt(lines[0].split(' ')[0]);
let t = new Array(10).fill(false);
for(let d of lines[1].split(' ')) t[parseInt(d)] = true;
for(; ; n++) {
	let m = n;
	while(m > 0) {
		let d = m % 10;
		if(t[d]) break;
		m = (m - d) / 10;
	}
	if(m == 0) break;
}
console.log(n);