jiahuimbzuai/CoQuIR huggingface dataset:
//  [ruby]
require "prime"
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N=gets.to_i
if N==1
    puts 0
    exit
elsif Prime.prime?(N)
    puts 1
    exit
end
n=N
table=Hash.new(false)
table[1]=true
ans=0
2.upto((N**0.5).to_i) do|i|
  k=i
  while not table[k] and (n%k).zero?
    n/=k
    table[k]=true
    k+=i
    ans+=1
  end
end
puts ans
//  [ruby]
require "prime"
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N=gets.to_i
if N==1
    puts 0
    exit
elsif Prime.prime?(N)
    puts 1
    exit
end
n=N
table=array((N**0.5)+1,false)
table[1]=true
ans=0
2.upto((N**0.5).to_i) do|i|
  k=i
  while not table[k] and (n%k).zero?
    n/=k
    table[k]=true
    k+=i
    ans+=1
  end
end
puts ans
//  [rust]
use proconio::input;

fn main() {
    input! {
        mut n: u64,
    }
    let mut v = vec![];
    calc(n, &mut v);

    let mut r = 0;
    for e in v {
        r += get_count(e);
    }

    println!("{}", r);
}

fn calc(n: u64, v: &mut Vec<u64>) {
    let sub = |n: u64, m: u64| -> (u64, u64) {
        let mut c = 0;
        let mut r = n;
        while r % m == 0 {
            c += 1;
            r /= m;
        }
        (c, r)
    };

    let (c, n) = sub(n, 2);
    if c > 0 {
        v.push(c);
    }
    let mut m = 3;
    let mut r = n;
    while m * m <= r {
        let (c, n) = sub(r, m);
        if c > 0 {
            v.push(c);
        }
        r = n;
        m += 2;
    }
    if r > 1 {
        v.push(1);
    }
}

fn get_count(n: u64) -> u64 {
    if n <= 2 {
        1
    } else if n <= 2 + 3 {
        2
    } else if n <= 2 + 3 + 4 {
        3
    } else if n <= 2 + 3 + 4 + 5 {
        4
    } else if n <= 2 + 3 + 4 + 5 + 6 {
        5
    } else if n <= 2 + 3 + 4 + 5 + 6 + 7 {
        6
    } else if n <= 2 + 3 + 4 + 5 + 6 + 7 + 8 {
        7
    } else if n <= 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 {
        8
    } else {
        9
    }
}
//  [rust]
#[allow(unused)]
use proconio::marker::*;
use proconio::{fastout, input};
#[allow(unused)]
use std::cmp::{max, min};
#[allow(unused)]
use std::collections::{HashMap, HashSet, VecDeque};

#[fastout]
fn main() {
    input! {
        n: i64,
    }
    let mut rec = vec![];
    factorization(n, &mut rec);

    let mut ans = 0;
    for r in rec {
        ans += help(r);
    }
    println!("{}", ans);
}

fn factorization(n: i64, rec: &mut Vec<i64>) {
    fn factor_sub(n: i64, m: i64) -> (i64, i64) {
        let mut c = 0;
        let mut x = n;
        while x % m == 0 {
            c += 1;
            x /= m;
        }
        (c, x)
    }

    let (c, n) = factor_sub(n, 2);
    if c > 0 {
        rec.push(c);
    }
    let mut x = 3;
    let mut m = n;
    while x * x <= m {
        let (c, n) = factor_sub(m, x);
        if c > 0 {
            rec.push(c);
        }
        m = n;
        x += 2;
    }
    if m > 1 {
        rec.push(1);
    }
}

fn help(n: i64) -> i64 {
    if n <= 2 {
        1
    } else if n <= 5 {
        2
    } else if n <= 9 {
        3
    } else if n <= 14 {
        4
    } else if n <= 20 {
        5
    } else if n <= 27 {
        6
    } else if n <= 35 {
        7
    } else if n <= 44 {
        8
    } else {
        9
    }
}
//  [rust]
#![allow(unused_imports)]
use proconio::input;
use std::collections::HashMap;
use ascii::*;

fn main() {
    input!(mut n: i64);
    if n == 1 {
        println!("0");
        return;
    }
    let mut factor_list: Vec<(i64, i64)> = Vec::new();
    let initial_n = n;
    let mut n_is_prime = true;
    for i in 2..=(f64::sqrt(n as f64) as i64) {
        let mut count = 0;
        while n % i == 0 {
            n /= i;
            count += 1;
            n_is_prime = false;
        }
        if count > 0 {
            factor_list.push((i, count));
        }
    }
    if n_is_prime {
        factor_list.push((initial_n, 1));
    }
    let mut count = 0;
    for item in factor_list.as_mut_slice() {
        let mut a = 1;
        while item.1 - a >= 0 {
            item.1 -= a;
            count += 1;
            a += 1;
        }
    }
    println!("{}", count);
}
//  [rust]
#![allow(unused_imports)]
use proconio::input;
use std::collections::HashMap;
use ascii::*;

fn main() {
    input!(mut n: i64);
    if n == 1 {
        println!("0");
        return;
    }
    let mut factor_list: Vec<(i64, i64)> = Vec::new();
    let initial_n = n;
    let mut n_is_prime = true;
    for i in 2..=(f64::sqrt(n as f64) as i64) {
        let mut count = 0;
        while n % i == 0 {
            n /= i;
            count += 1;
            n_is_prime = false;
        }
        if count > 0 {
            factor_list.push((i, count));
        }
    }
    if n_is_prime {
        factor_list.push((initial_n, 1));
    }
    let mut count = 0;
    for item in factor_list.as_mut_slice() {
        let mut a = 1;
        while item.1 - a >= 0 {
            item.1 -= a;
            count += 1;
            a *= 2;
        }
    }
    println!("{}", count);
}
//  [rust]
use proconio::{input, fastout};

fn is_prime(i: f64) -> bool {
    let i_int = i as i64;
    let end = i.sqrt() as i64;
    let mut flag = true;
    for j in 2..end {
        if i_int % j == 0 {
            flag = false;
            break;
        }
    }

    return flag;
}
fn prime_factorization(n: f64) -> i64 {
    let mut _n = n;
    let mut i = 2.0_f64;
    let mut count = 1;
    if _n == 1.0 {
        count = 0;
    }
    while _n.sqrt() > i {
        if _n % i == 0.0 && is_prime(i) {
            _n = _n / i;
            count += 1;
        }
        i += 1.0;
    }
    return count;
}

#[fastout]
fn main() {
    input!{
        n: f64,
    }
    println!("{}", prime_factorization(n));

}
//  [swift]
var N = Int(readLine()!)!
var p = 2
var ans = 0
while p * p < N {
    var z = p
    while N % z == 0 {
        ans += 1
        N /= z
        z *= p
    }
    while N % p == 0 {
        N /= p
    }
    p += 1
}
print(N > 1 ? ans + 1 : ans)
//  [swift]
import Foundation
// 第一引数に、素因数分解したい自然数を渡す
func prime_factorization(n:Int)->[[Int]]{
    // n = 1 なら素因数分解できないので空の二次元配列を返す
    if n == 1{
        return []
    }
    // 戻り値のなる二次元配列を初期化
    var arr:[[Int]] = []
    // nの値を変数に格納
    var temp = n
    // 計算するのは√nまでで十分
    for i in 2...Int(sqrt(Double(n)))+1{
        // 割り切れる -> その数を素因数に持つ
        if temp%i==0{
            var cnt=0
            // 素因数の字数を計算
            while temp%i==0{
                // 割り切れるなら次数を一つ増やす
                cnt+=1
                // tempをiで割る
                temp /= i
            }
            // 素因数とその次数をarrに追加
            arr.append([i,cnt])
        }
    }
    // temp ≠ 1ならtempは素因数なのでarrに追加
    if temp != 1{
        arr.append([temp, 1])
    }
    // arrが空なら n = (素数) なのでarrに追加
    if arr==[] {
        arr.append([n, 1])
    }
    // arrを返す
    return arr
}

// 標準入力の受け取り
let n = Int(readLine()!)!

// nを素因数分解
let factorization = prime_factorization(n:n)

// 答えを入れる変数の初期化
var ans = 0

// 各素因数についてループを回す
for i in factorization{

    // 計算に使う変数を初期化
    var num = i[1]
    var cnt = 1
    
    // もし以前の操作で選んだどの整数とも異なる整数を作れるなら ans += 1
    while num >= cnt{
        ans += 1
        num -= cnt
        cnt += 1
    }
}

// 答えを出力
print(ans)
//  [swift]
import Foundation

func sieve(_ x: Int) -> [Bool] {
    let sq = Int(sqrt(Double(N)) + 0.1)
    var array = Array(repeating: true, count: x)
    array[0] = false; array[1] = false
    for p in 2..<sq {
        if !array[p] { continue }
        for i in stride(from: p * p, to: x, by: p) {
            array[i] = false
        }
    }
    return array
}
//　因数分解！

var N = Int(readLine()!)!
var i = 0
var r = 0
if N != 1 {
    let s = sieve(N).enumerated().filter(\.1).map(\.0)
    
    for p in s {
        if N.isMultiple(of: p) {
            while N.isMultiple(of: p) {
                N = N / p
            }
            r += 1
        }
        i += 1
        if N == 1 { break }
    }
    print(r)
} else {
    print(0)
}
//  [typescript]
import * as fs from 'fs';

const readString = (() => {
  const input = fs.readFileSync(0).toString();
  const words = input.split(/[ \n]/);
  let i = 0;
  return () => words[i++] || '';
})();
const readInt = () => parseInt(readString(), 10);
const readBigInt = () => BigInt(readString());

const gcd = (a: bigint, b: bigint) => {
  const _gcd = (a: bigint, b: bigint): bigint => {
    const q = a % b;
    return q === 0n ? b : _gcd(b, q);
  };
  return a > b ? _gcd(a, b) : _gcd(b, a);
};

const MOD = 1000000007;
const MOD_BIGINT = BigInt(MOD);
class ModBigInt {
  constructor(public v: bigint) {}

  static of(n: number | bigint) {
    return new ModBigInt(ModBigInt.toBigInt(n));
  }

  static toBigInt(other: number | bigint | ModBigInt) {
    if (typeof other === 'bigint') return other;
    if (typeof other === 'number') return BigInt(other);
    return other.v;
  }

  clone = () => new ModBigInt(this.v);
  plus = (other: number | bigint | ModBigInt) => {
    this.v = (this.v + ModBigInt.toBigInt(other)) % MOD_BIGINT;
    return this;
  };
  minus = (other: number | bigint | ModBigInt) => {
    this.v = (this.v + MOD_BIGINT - ModBigInt.toBigInt(other)) % MOD_BIGINT;
    return this;
  };
  multiply = (other: number | bigint | ModBigInt) => {
    this.v = (this.v * ModBigInt.toBigInt(other)) % MOD_BIGINT;
    return this;
  };
  pow = (other: number) => {
    const v = mod(1);
    for (let i = 0; i < other; i++) v.multiply(this.v);
    return v;
  };
}

const mod = ModBigInt.of;

const abs = (a: bigint) => (a > 0n ? a : -a);

const count = (s: number) => {
  return Math.floor(Math.sqrt(2 * s + 0.25) - 0.5);
};

(function main() {
  let N = readInt();
  const s: { [p: number]: number } = {};
  for (let p = 2; p <= 1000000; p++) {
    while (N % p === 0) {
      N /= p;
      s[p] = s[p] || 0;
      s[p]++;
    }
    if (N === 1) break;
  }

  let result = 0;
  for (const p of Object.keys(s) as any) {
    result += count(s[p]);
  }
  if (N > 1) result += 1;
  console.log(result);
})();
//  [typescript]
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const primeFactorize = (target: bigint) => {
  let n = target;
  const res = new Map<bigint, bigint>();

  for (let i = 2n; i * i <= n; i++) {
    if (n % i !== 0n) {
      continue;
    }

    let ex = 0n;
    while (n % i === 0n) {
      ex += 1n;
      n /= i;
    }

    res.set(i, ex);
  }

  if (n !== 1n) {
    res.set(n, 1n);
  }

  return res;
};

const main = (input: string[][]) => {
  const N = BigInt(input[0][0]);

  const pf = primeFactorize(N);

  let answer = 0;

  pf.forEach((ex) => {
    let usedEx = 1;
    let usedCount = 0;

    while (usedEx <= ex) {
      usedCount += 1;
      usedEx += usedCount + 1;
    }

    answer += usedCount;
  });

  return answer;
};

console.log(main(read()));
//  [typescript]
import * as fs from 'fs'

function main(input: string[][]) {
  const N = Number(input[0][0])
  let n = N
  let count = 0
  for (let i = 2; i < N; i += 1) {
    let divisor = i
    while (n % divisor === 0) {
      count += 1
      n = n / divisor
      divisor = divisor * i
    }
    if (i > n) break
  }

  console.log(count)
  return
}

main(
  fs
    .readFileSync('/dev/stdin', 'utf8')
    .trim()
    .split('\n')
    .map((i) => i.split(' '))
)
//  [typescript]
class AtCoder {
  constructor() {
      // 入力系
      this.input = require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/);
      this.input_i = -1;
  }
  n() {
      this.input_i++;
      return Number(this.input[this.input_i]);
  }
  nn(n) {
      const a = [];
      for (let i = 0; i < n; i++) {
          a.push(this.n());
      }
      return a;
  }
  s() {
      this.input_i++;
      return String(this.input[this.input_i]);
  }
  ss(n) {
      const a = [];
      for (let i = 0; i < n; i++) {
          a.push(this.s());
      }
      return a;
  }
  // コンソール
  o(...a) {
      console.log(...a);
  }
  // Math
  abs(a) {
      return Math.abs(a);
  }
  min(...a) {
      return Math.min(...a);
  }
  max(...a) {
      return Math.max(...a);
  }
  floor(a) {
      return Math.floor(a);
  }
  ceil(a) {
      return Math.ceil(a);
  }
  round(a) {
      return Math.round(a);
  }
  // ソート
  asc(ar) {
      const t = [...ar];
      ar.sort((a, b) => { return a - b; });
  }
  desc(ar) {
      const t = [...ar];
      ar.sort((a, b) => { return b - a; });
  }
  // 自作
  gcd(...arr) {
      for (let i = 0; i < arr.length - 1; i++) {
          let [x, y] = [arr[i], arr[i + 1]];
          while (y) {
              [x, y] = [y, x % y];
          }
          arr[i + 1] = x;
      }
      return arr[arr.length - 1];
  }
  ;
  lcm(...arr) {
      for (let i = 0; i < arr.length - 1; i++) {
          let [x, y] = [arr[i], arr[i + 1]];
          while (y) {
              [x, y] = [y, x % y];
          }
          arr[i + 1] = arr[i] * arr[i + 1] / x;
      }
      return arr[arr.length - 1];
  }
  ;
  isPrime(n) {
      if (n < 2)
          return false;
      const suq = Math.sqrt(n);
      for (let i = 2; i <= suq; i++) {
          if (n % i == 0) {
              return false;
          }
      }
      return true;
  }
  ;
  deduplicate(a) {
      return Array.from(new Set(a));
  }
  ;
  f(roop, callback) {
      for (let i = 0; i < roop; i++) {
          callback(i);
      }
  }
  ;
  Yes() {
      console.log('Yes');
  }
  No() {
      console.log('No');
  }
  YES() {
      console.log('YES');
  }
  NO() {
      console.log('NO');
  }
}
const m = () => {
  function pf(n) {
      let ob = {};
      var init = 2;
      while (n !== 1) {
          var i = init;
          while (i < Number.MAX_SAFE_INTEGER) {
              if (n % i == 0 || i > 1000000) {
                  if (!ob[i]) {
                      ob[i] = 1;
                  }
                  else {
                      ob[i] = ob[i] + 1;
                  }
                  n = n / i;
                  break;
              }
              i = i + 1;
          }
          init = i;
      }
      return ob;
  }
  const o = new AtCoder();
  let n = o.n();
  if (n == 1) {
      return o.o(0);
  }
  if (o.isPrime(n)) {
      return o.o(1);
  }
  let ob = pf(n);
  let ans = 0;
  Object.keys(ob).forEach((key) => {
      let t = 1;
      while (ob[key] >= 0) {
          ob[key] -= t;
          t++;
          if (ob[key] >= 0)
              ans++;
      }
  });
  o.o(ans);
};
m();
//  [python]
N,K=input().split()
nums = input().split()
cand = list(map(str,list(x for x in range(10))))
for num in nums:
  if num in cand:
    cand.remove(num)
work = []
if int(N) <= int(cand[-1]*len(N)):
  for i in range(len(N)):
    for c in cand:
      if int(N[i]) == int(c):
        work.append(c)
        break
      elif int(N[i]) < int(c):
        work.append(c)
        for j in range(i+1,len(N)):
          work.append(cand[0])
        print(''.join(work))
        exit()
else:
  if cand[0] != '0':
    work.append(cand[0])
  else:
    work.append(cand[1])
  for i in range(len(N)):
    work.append(cand[0])
print(''.join(work))
//  [python]
n,k=map(int,input().split())
d=list(map(int,input().split()))

num=[]
for i in range(10):
    if i not in d:
        num.append(i)
#print(num)
num.sort()
digit=len(str(n))
ns=str(n)

ans=''
cnt=0
while cnt<digit:

    for i in num:
        if int(ns[cnt])>i:continue
        if int(ns[cnt])==i:
            ans+=str(i)
            break
        else:
            ans+=str(i)+(digit-cnt-1)*str(num[0])
            cnt=digit
            break
    else:
        ans=str(num[0]) if num[0]!=0 else str(num[1])
        ans+=str(num[0])*digit
        cnt=digit
    cnt+=1
print(ans)
//  [python]
import math

total = list(map(lambda x: int(x), input().split()))
possible = list({0,1,2,3,4,5,6,7,8,9} - set(list(map(lambda x: int(x), input().split()))))
yen = [int(d) for d in str(total[0])]

i = 0
if yen[0] == 9 and 9 not in possible:
    zeros = [0] * len(yen)
    yen = [1] + zeros
    print(int(''.join(map(str, yen))))


while i < len(yen):
    if yen[i] not in possible:
        if yen[i] == 9 and i != 0:
            yen[i - 1] += 1
            for i in range(i, len(yen)):
                yen[i] = 0
        elif yen[i] != 9:
            for j in possible:
                if j > i:
                    yen[i] = j
    i = i + 1
        
                
                
            
            




print(int(''.join(map(str, yen))))
//  [java]
import java.util.*;
import java.io.*;
class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        
        int N = Integer.parseInt(st.nextToken());
        int K = Integer.parseInt(st.nextToken());

        boolean[] dislike = new boolean[10];
        st = new StringTokenizer(br.readLine());

        for(int i=0; i<K; i++){
            int d = Integer.parseInt(st.nextToken());
            dislike[d]=true;
        }

        int ans = 0;
        String n = Integer.toString(N);
        boolean inc=false;
        boolean raised=false;
        for(int i=0; i<n.length(); i++){
            int cur = n.charAt(i)-'0';
            int k=cur;
            if(raised)
                k=0;
            while(k<10){
                if(!dislike[k]){
                    ans=ans*10+k;
                    break;
                }
                k++;
            }
            if(k!=cur)
                raised=true;
            if(k==10){
                inc=true;
                k=0;
                while(k<10){
                    if(!dislike[k]){
                        ans=ans*10+k;
                        break;
                    }
                    k++;
                }
            }
        }
        if(inc){
            int k=0;
            while(k<10){
                if(!dislike[k]){
                    ans=ans*10+k;
                    break;
                }
                k++;
            }
        }
        System.out.println(ans);

    }
}
//  [java]
import java.io.*;
import java.util.*;

public class Main {
  static int MOD = 1000000007;
  static double EPS = 1e-9;

  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

    StringTokenizer st = new StringTokenizer(in.readLine());

    String N = st.nextToken();
    int length = N.length();
    int K = Integer.parseInt(st.nextToken());

    TreeSet<Integer> set = new TreeSet<Integer>();

    st = new StringTokenizer(in.readLine());

    for (int i = 0; i < K; i++) {
      set.add(Integer.parseInt(st.nextToken()));
    }

    int[] valid = new int[10 - K];
    int index = 0;

    for (int i = 0; i < 10; i++) {
      if (!set.contains(i)) {
        valid[index] = i;
        index++;
      }
    }

    // System.out.println(Arrays.toString(valid));


    int res = 0;
    /*int max = -1;

    for (int i = 0; i < length; i++) {
      max = Math.max(max, N.charAt(i) - '0');
    }

    if (max > valid[valid.length - 1]) {
      res = valid[]
    } */

    boolean b = true;
    boolean large = false;

    for (int i = 0; i < length; i++) {
      int d = N.charAt(i) - '0';
      // System.out.println(d);
      boolean done = false;
      if (large) {
        res = res * 10 + valid[0];
        continue;
      }
      for (int j = 0; j < valid.length; j++) {
        if (valid[j] >= d) {
          if (i == 0 && valid[j] > d)
            large = true;
          res = res * 10 + valid[j];
          done = true;
          break;
        }
      }
      if (!done) {
        b = false;
        break;
      }
    }

    if (!b) {
      if (valid[0] == 0)
        res = valid[1];
      else
        res = valid[0];
      for (int i = 0; i < length; i++) {
        res = res * 10 + valid[0];
      }
    }

    System.out.println(res);

    in.close();
  }
}
//  [java]
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());
		int k = Integer.parseInt(st.nextToken());
		boolean[] bad = new boolean[10];
		st = new StringTokenizer(br.readLine());
		for (int i = 0; i < k; i++) {
			int d = Integer.parseInt(st.nextToken());
			bad[d] = true;
		}
		for (int x = n; ; x++) {
			boolean yes = true;
			for (int y = x; y > 0; y /= 10) {
				int d = y % 10;
				if (bad[d]) {
					yes = false;
					break;
				}
			}
			if (yes) {
				System.out.println(x);
				return;
			}
		}
	}
}
//  [java]
import java.io.BufferedReader;

import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.TreeSet;

public class Main {
	public static int convertTo (ArrayList<Integer> a) {
		int result = 0 ; 
		for(int i = a.size()-1; i >= 0 ; i --) {
			result += (int)(a.get(i)*(Math.pow(10,i)));
		}
		return result ;
	} 
	public static void main(String[]args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] a = br.readLine().split(" ");
        int N = Integer.parseInt(a[0]);
        int r = N ;
        int K = Integer.parseInt(a[1]);
        HashSet<Integer> kNumbers = new HashSet<>();
        TreeSet<Integer> nNumbers = new TreeSet<>();
        String[] b = br.readLine().split(" ");
        for(int i = 0 ; i < K ; i ++) {
        	kNumbers.add(Integer.parseInt(b[i]));
        }
        for(int i = 0 ; i <= 9 ; i ++) {
        	if(!kNumbers.contains(i)) {
        		nNumbers.add(i);
        	}
        }
        ArrayList<Integer> number = new ArrayList<Integer>();
        while(N!= 0) {
        	 number.add(N%10);
        	  N/=10;
        }
        
        while(true) {
        	int c = 0 ;
        	for(int i = 0 ; i < number.size() ; i++) {
        		if(kNumbers.contains(number.get(i))) {
        			if(nNumbers.ceiling(number.get(i)) == null) {
        				number.set(i,nNumbers.floor(number.get(i)));
        				System.out.print(number.get(i));
        			}
        			else
        				number.set(i,nNumbers.ceiling(number.get(i)));
        		}
        		else {
        			c++ ;
        		}
        	}
        	if(c == number.size() && convertTo(number) >= r) {
        		System.out.print(convertTo(number));
        		break;
        	}
	}     
	}
}
//  [java]
import java.util.*;
public class Main{

  public static void main(String[] args) {
   Scanner no=new Scanner(System.in);
   StringBuilder sb=new StringBuilder();
   int n=no.nextInt();
   int m=no.nextInt();
   int min=0;
   int arr[]=new int[10];
   for(int i=0;i<m;i++){
     arr[no.nextInt()]++;
   }
   int j=n;
   int u=j;
   for(j=n;j<10000;j++){
    //System.out.println(j);
    u=j;
     while(u!=0){
       if(arr[u%10]>0){
         break;
       }
       else{
         //System.out.println("h");
         u=u/10;
       }
     }
     if(u==0){
       break;
     }
   }
   if(u==0){
     System.out.println(j);
   }
  }

}
//  [cpp]
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
//const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;

int main(){
    string N;
    int K;
    cin >> N >> K;
    set<int> D;
    rep(i, 0, K) {
        int x;
        cin >> x;
        D.insert(x);
    }
    int mini = 0, mini2 = 1;
    rep(i, 0, 10){
        if (D.count(mini)){
            mini++;
        }
        else{
            break;
        }
    }
    rep(i, 0, 10){
        if (D.count(mini2)){
            mini2++;
        }
        else{
            break;
        }
    }
    
    int m = N.size();
    vector<int> n(m + 1, 0);
    rep(i, 1, m + 1){
        n.at(i) = N.at(i - 1) - '0';
    }
    bool can = false;
    
    rep(i, 1, m + 1){
        if(D.count(n.at(i))){
            while(D.count(n.at(i))){
                SKIP:
                n.at(i)++;
                if (n.at(i) == 10){
                    n.at(i) = mini;
                    n.at(i - 1)++;
                    if (D.count(n.at(i - 1))){
                        i--;
                        goto SKIP;
                    }
                }
            }
            rep(j, i + 1, m + 1){
                n.at(j) = mini;
            }
            break;
        }
    }
    SKIP1:
    if (n.at(0) != 0){
        cout << mini2;
    }
    rep(i, 1, m + 1){
        cout << n.at(i);
    }
    cout << endl;
}
//  [cpp]
#include <bits/stdc++.h>

#define ll long long
#define mk make_pair
#define pb push_back
#define ff first
#define sc second
#define all(x) x.begin(), x.end()

ll gcd(ll a, ll b){
   if(b == 0) return a;
   
   return gcd(b, a % b);
}

ll sum(int n){
   if(n == 0){
      return n;
   }else{
      return sum(n/10) + n%10;
   }
}
using namespace std;


int disl[10] = {1,1,1,1,1,1,1,1,1,1};//1's like 0's dislike
bool verify(int n){
   while(n > 0){
      if(disl[n%10] == 0) return false;
      n/=10;
   }
   return true;
}

int main(){
   
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);

   int n; cin >> n;
   int k; cin >> k;
   while(k--){
      int dint; cin >> dint;
      disl[dint] = 0;  
   }
   
   for(int i = n; ; i++){
      if(verify(i)){
         cout << i; break;
      }
   }
   return 0;
}
//  [cpp]
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include <set>

#define DIV 1000000007
using namespace std;
using ll = long long;

int main() {
	int N, K;
	cin >> N >> K;

	vector<bool> deg(10, true);
	for (int i = 0; i < K; i++) {
		int d;
		cin >> d;
		deg[d] = false;
	}

	int ans;
	bool flag = false;
	for (ans = N; !flag; ans++) {
		int temp = ans;
		flag = true;
		while (temp > 0) {
			if (!deg[temp % 10]) {
				flag = false;
				break;
			}
			temp /= 10;
		}
	}

	cout << ans-1 << endl;
}
//  [cpp]
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
long long int power(int a,int b)
{
    if(b==0)
        return 1;
    long long int k=power(a,b/2);
    if(b%2==0)
        return ((k%M)*(k%M))%M;
    else
        return ((k%M)*(k%M)*(a%M))%M;
}
long long int fact(long long int n)
{
    if(n==1 || n==0)
        return 1;
    else
        return ((n%M)*(fact(n-1)%M))%M;

}
int div(int n)
{  int c=0;
    for(int i=1;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
          if(n/i==i)
            c++;
          else
            c+=2;
        }

    }

    
    return  c;
}
int func(int n)
{
    return (n*(n+1))/2;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     #ifndef ONLINE_JUDGE
 
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
 
   #endif
           
        string str;
        cin>>str;
        int n;
        cin>>n;
        bool arr[10];
        memset(arr,1,sizeof(arr));
        for(int i=0;i<n;i++)
        {
            int h;
            cin>>h;
            arr[h]=0;
        }
        for(int i=0;i<str.length();i++)
        {

            for(int j=0;j<=9;j++)
            {
                if(arr[j]==1 && (str[i]-48)<=j)
                {
                    str[i]=char(48+j);
                    break;
                }
            }
        }
       cout<<str;

 return 0;
}
//  [cpp]
#include<bits/stdc++.h>
using namespace std;
#define fori(x,y)   for(ll i=x;i<y;i++)
#define forj(x,y)   for(ll j=x;j<y;j++)
#define rfori(a,b)   for(int i=a;i>=b;i--)
#define for_it(a)     for(auto it: a)
#define pb          push_back
#define pf          push_front
#define ff          first
#define ss          second
#define all(x)      x.begin(),x.end()
#define mp          make_pair
#define mod         1000000007
#define mem(a,b)    memset(a,b,sizeof(a))
#define ld          long double
#define endl        "\n"
#define ll          long long
#define llu         unsigned long long 
#define pii         pair<int,int>
#define pll         pair<ll,ll>
#define vl          vector<ll> 
#define vi          vector<int> 
#define vc          vector<char> 
#define vs          vector<string> 
#define si          set<int>
#define spii        set<pii>
#define usi         unordered_set<int>
#define usl         unordered_set<ll>
#define uspii       unordered_set<pii>
#define mii         map<int,int>
#define umii        unordered_map<int,int>
#define pqmx        priority_queue<int>
#define pqmn        priority_queue<int,vi,greater<int>>
#define setbits(x)  __builtin_popcountll(x)
#define fast        ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define testcase    int test;cin>>test;for(ll tst=0;tst<test;tst++)
int xx[4]={0,0,1,-1};
int yy[4]={-1,1,0,0};

/*-----------------------------------------------------------------------------------------------------------------*/



int main()
{
	#ifndef ONLINE_JUDGE
	freopen("C_IN.txt","r",stdin);
	freopen("C_Out.txt","w",stdout);
	#endif
	fast;

	ll n,m;
	cin>>n>>m;
	vl v(10,0);
	fori(0,m)
	{
		int x;
		cin>>x;
		v[x]++;
	}
	ll res=0,b=1;
	while(n)
	{
		int rem=n%10;
		if(v[rem])
		{
			rem++;
		}
		res+=rem*b;
		b*=10;
		n=n/10;
	}
	cout<<res<<endl;
	return 0;
}
//  [cpp]
#include<bits/stdc++.h>
using namespace std;
#define fori(x,y)   for(ll i=x;i<y;i++)
#define forj(x,y)   for(ll j=x;j<y;j++)
#define rfori(a,b)   for(int i=a;i>=b;i--)
#define for_it(a)     for(auto it: a)
#define pb          push_back
#define pf          push_front
#define ff          first
#define ss          second
#define all(x)      x.begin(),x.end()
#define mp          make_pair
#define mod         1000000007
#define mem(a,b)    memset(a,b,sizeof(a))
#define ld          long double
#define endl        "\n"
#define ll          long long
#define llu         unsigned long long 
#define pii         pair<int,int>
#define pll         pair<ll,ll>
#define vl          vector<ll> 
#define vi          vector<int> 
#define vc          vector<char> 
#define vs          vector<string> 
#define si          set<int>
#define spii        set<pii>
#define usi         unordered_set<int>
#define usl         unordered_set<ll>
#define uspii       unordered_set<pii>
#define mii         map<int,int>
#define umii        unordered_map<int,int>
#define pqmx        priority_queue<int>
#define pqmn        priority_queue<int,vi,greater<int>>
#define setbits(x)  __builtin_popcountll(x)
#define fast        ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define testcase    int test;cin>>test;for(ll tst=0;tst<test;tst++)
int xx[4]={0,0,1,-1};
int yy[4]={-1,1,0,0};

/*-----------------------------------------------------------------------------------------------------------------*/



int main()
{
	#ifndef ONLINE_JUDGE
	freopen("C_IN.txt","r",stdin);
	freopen("C_Out.txt","w",stdout);
	#endif
	fast;

	ll n,m;
	cin>>n>>m;
	vl v(10,0);
	fori(0,m)
	{
		int x;
		cin>>x;
		v[x]++;
	}
	int res=0,b=1;
	while(n)
	{
		int rem=n%10;
		if(v[rem])
		{
			rem++;
		}
		res+=rem*b;
		b*=10;
		n=n/10;
	}
	cout<<res<<endl;
	return 0;
}
//  [c]
#include <stdio.h>
#include <stdbool.h>

int n;  /* 商品の金額 */
int k;  /* 嫌いな数字の個数を指定 */
int k_array[10]; /* 嫌いな数を指定する */

bool num_chcek(int n){
    while(n > 0){   /* 0より大きい間ループ */
        for(int i = 0; i < k; i++){
            if(n%10 == k_array[i]){ /* n/10の剰余 */
                return false;   /* 0 */
            }
        }
        n /= 10;   /* 桁ずらし */
    }
    return true;    /* 1 */
}

int main(){
    scanf("%d%d",&n,&k);
    for(int i = 0;i < k; i++){
        scanf("%d",&k_array[i]);   
    }
    
    for(int i = n;;i++){
        if(num_chcek(i)){   /* trueなら出力 */
            printf("%d\n",i);
            break;
        }   
    }
}
//  [c]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
#define absl(v) labs((v))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(cv *a, cv *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(cv *a, cv *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(cv *left, cv *right) {return strcmp((char *)left,(char *)right);}
int downchar(cv *left, cv *right) {return strcmp((char *)right,(char *)left);}
void tmpInit(int *c,ll m) {ll i;rep(i,m) c[i]=i;}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1){
      res *= a; if(mod>=1) res %= mod;
    }
    a *= a; if(mod>=1) a %= mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
    
}
int a[LIMIT2]={0};
ll k;
int find(ll price){
  ll i,j;
  j=price%10;
  if(price<=0) return 1;
  rep(i,k) if(a[i]==j) return 0;
  return find(price/10);
}
int main(void){
  initialize();
  ll n,m,i,j,result=0;
  char s[LIMIT1];
  
  scanf("%lld %lld",&n,&k);
  rep(i,k) scanf("%d",&a[i]);
  i=n;
  while(1){
    if(find(i)==1){
      result = i;
      break;
    }
    i++;
  }
  printf("%lld\n",result);
  return 0;
}
//  [c]
#include <stdio.h>

int search(int n,int k,int *hate){
  int i;
  for(i=0;i<k;i++){
    if(n==hate[i]){
      return 1;
    }
  }
  return 0;
}

int main(){
  int hate[9];
  int n,k,i,ok=0,tmp;
  
  scanf("%d %d",&n,&k);
  for(i=0;i<k;i++){
    scanf("%d",&hate[i]);
  }
  
  while(ok==0){
    ok=1;
    tmp=n;
    while(0<tmp){
      if(search(tmp%10,k,hate)==1){
        ok=0;
        n++;
        break;
      }
      tmp=tmp/10;
    }
  }
  
  printf("%d",n);
}
//  [c]
#include <stdio.h>
#include <stdbool.h>

int banum[10];
bool judge (int N,int K) {
    while (N > 0) {
        for (int i = 0; i < K; i++) {
            if (N % 10 == banum[i])
                return false;
        }
        N /= 10;
    }
    return true;
}

int main(void)
{
   int N, K;
    scanf("%d %d", &N, &K);
    for (int i = 0; i < K; i++)
        scanf("%d", &banum[i]);
    for (int i = N;; i++) {
        if (judge(N, K)) {
            printf("%d", N);
            return 0;
        }
    }
}
//  [c]
#include <stdio.h>
#include <stdbool.h>

int banum[10];
bool judge (int N,int K) {
    while (N > 0) {
        for (int i = 0; i < K; i++) {
            if (N % 10 == banum[i])
                return false;
        }
        N /= 10;
    }
    return true;
}

int main(void)
{
   int N, K;
    scanf("%d %d", &N, &K);
    for (int i = 0; i < K; i++)
        scanf("%d", &banum[i]);
    for (int i = N;; i++) {
        if (judge(N, K)) {
            printf("%d", N);
            break;
        }
    }
    return 0;
}
//  [c]
#include<stdio.h>
int main()
{
    int n,k,i,j,s=0,t,m=0,p=0,q=0,e,u,v;
    scanf("%d%d",&n,&k);
    int pt[k],pl[10],po[10];
    for(i=0;i<k;i++)
    {
        scanf("%d",&pt[i]);
    }
    for(i=0;i<=9;i++)
    {
        for(j=0;j<k;j++)
       {
           if(i==pt[j])
           {
               p=1;
               break;
           }
       }
       if(p==0)
       {
           po[q] = i;
           q++;
       }
       else
       {
           p = 0;
           continue;
       }
   }
    for(i=0;i<=q;i++)
    {
        for(j=i+1;j<q;j++)
        {
            if(po[i]>po[j])
            {
                e = po[i];
                po[i] = po[j];
                po[j] = e;
            }
        }
    }
    for(i=0;n!=0;i++)
    {
        pl[i] = n%10;
        for(j=0;j<k;j++)
        {
            u = n/10;
            if(pl[i]==pt[j] && u!=0)
            {
                pl[i] = po[0];
                break;
            }
            if(pl[i]==pt[j] && u==0)
            {
                pl[i] = pl[i] +1;
                j = -1; 
            }
        }
        n = n/10;
        m++;
    }
    for(i=m-1;i>=0;i--)
    {
        printf("%d",pl[i]);
    }
    return 0;
}
//  [javascript]
'use strict'

const main = (INPUT) => {
  const input = INPUT.split('\n')
  const N = input[0].split(' ')[0].split('').map(n => Number(n)).reverse()
  const D = input[1].split(' ').map(n => Number(n))
  const ary = []
  for (let i = 0; i <= 9; i++) {
    if (D.indexOf(i) == -1) {
      ary.push(i)
    }
  }
  let flag
  for (let i = 0; i < N.length; i++) {
    while (true) {
      if (ary.indexOf(N[i]) >= 0) {
        if (flag && i == N.length - 1) {
          for (let j = 0; j < i; j++) {
            N[j] = ary[0]
          }
          i = 0
          flag = false
          continue
        }
        break
      }
      N[i] = N[i] + 1
      flag = true
      if (N[i] >= 10) {
        if (i == N.length - 1) {
          N.push(1)
          N[i] = 0
        } else {
          N[i + 1] = N[i + 1] + 1
          N[i] = 0
        }
      }
    }
  }

  console.log(N.reverse().join(''))
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))
//  [javascript]
'use strict;'
function main() {
  const input = require("fs").readFileSync("/dev/stdin", "utf-8").trim();
  const lines = input.split('\n');
  const totalNum = lines[0].split(' ')[0];
  const dislikeNum = lines[1].split(' ');
  const likeNum = [];
  for(var i = 0; i < 10; i++) {
    if(dislikeNum.indexOf(i + '') === -1) {
      likeNum.push(i + '');
    }
  }
  // var res = totalNum;
  // while(1) {
  //  var noMatch = false;
  //  for(var i = 0; i < res.length; i++) {
  //    if(dislikeNum.indexOf(res[i]) > -1) {
  //      res = parseInt(res) + 1;
  //      res = res + '';
  //      noMatch = true;
  //      break;
  //    }
  //  }
  //  if(!noMatch) {
  //    break;
  //  }
  // }
  // console.log(res);
  const res = getResult(totalNum, likeNum);
  if(res.flag) {
    console.log(likeNum[0] === '0' ? likeNum[1] + res.str : likeNum[0] + res.str);
  } else {
    console.log(res.str);
  }
}

function getResult(sourceNum, likeNum) {
  const item = sourceNum[0];
  const resObj = sourceNum.length - 1 ? getResult(sourceNum.slice(1), likeNum) : {};
  const resStr = resObj.str || '';
  const flag = resObj.flag;
  if(!flag) {
    if(likeNum.indexOf(item) > -1) {
      return {
        str: item + resStr,
        flag: false
      };
    } else {
      var bigger = getBigger(likeNum, item);
      if(bigger) {
        var str = '';
        for(var i = 0; i < resStr.length; i++) {
          str += likeNum[0];
        }
        return {
          str: bigger + str,
          flag: false
        };
      } else {
        var str = '';
        for(var i = 0; i < resStr.length; i++) {
          str += likeNum[0];
        }
        return {
          str: likeNum[0] + str,
          flag: true
        };
      }
    }
  } else {
    var bigger = getBigger(likeNum, item);
    if(bigger) {
      var str = '';
      for(var i = 0; i < resStr.length; i++) {
        str += likeNum[0];
      }
      return {
        str: bigger + str,
        flag: false
      };
    } else {
      var str = '';
      for(var i = 0; i < resStr.length; i++) {
        str += likeNum[0];
      }
      return {
        str: likeNum[0] + str,
        flag: true
      };
    }
  }
}

function getBigger(arr, num) {
  for(var i = 0; i < arr.length; i++) {
    if(arr[i] > num) {
      return arr[i] + ''
    }
  }
  return null;
}

main();
//  [javascript]
function Main(s) {
	s[0] = s[0].split(" ").map(a => parseInt(a));
	s[1] = s[1].split(" ").map(a => parseInt(a));
	var n = s[0][0];
	var k = s[0][1];
	var sl = s[1].length;
	while(f(n)) n++;
	
	console.log(n);
	
	function f(k){
		while(k){
			var m = k % 10;
			for(var i = 0; i < sl; i++){
				if(m === s[1][i]) return true;
			}
			k = Math.floor(k * 0.1);
		}
	}
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").split("\n"));
//  [javascript]
function main(input) {
    let [totalPrice , length] = input.split("\n")[0].split(" ").map( v => Number(v));
    
    const list = JSON.parse(JSON.stringify(input.split("\n")[1].split(" ").map(v => Number(v))));
    const hateNumbers = { list, length };
    // const favoriteNumber = Array.from({ length: 10 }, (v, i) => i);
    // favoriteNumber.filter(v => hateNumbers.list.includes(v) ? false : true)

    const matches = new RegExp(`[${hateNumbers.list.join("")}]`);
    while (matches.test(totalPrice.toString())) {
        totalPrice++;
    }
    console.log('totalPrice', totalPrice);

}


// let input = "1000 8" + '\n' +
//     "1 3 4 5 6 7 8 9";
// main(input);
main(require("fs").readFileSync("/dev/stdin","utf8"));
//  [javascript]
function main() {
  process.stdin.resume();
  process.stdin.setEncoding("utf8");
  var chunks = "";

  process.stdin.on("data", function (chunk) {
    chunks += chunk;
  });

  process.stdin.on("end", function () {
    var inputs = chunks.trim().split("\n");
    var number = inputs[0].split(" ")[0].split("");
    var ks = inputs[1].split(" ").map((k) => parseInt(k, 10));
    var ans = [];

    var carry = false;
    for (i = number.length - 1; i >= 0; i--) {
      var n = parseInt(number[i], 10);
      if (carry) {
        n = n + 1;
        if (n >= 10) {
          n = 10 - n;
          carry = true;
        } else {
          carry = false;
        }
      }

      while (true) {
        if (ks.find((k) => k === n)) {
          n = n + 1;
          if (n >= 10) {
            n = 10 - n;
            carry = true;
          }
        } else {
          ans.unshift(n);
          break;
        }
      }
    }

    if (carry) {
      ans.unshift(1);
    }

    console.log(parseInt(ans.join(""), 10));
  });
}

main();
//  [javascript]
function main() {
  process.stdin.resume();
  process.stdin.setEncoding("utf8");
  var chunks = "";

  process.stdin.on("data", function (chunk) {
    chunks += chunk;
  });

  process.stdin.on("end", function () {
    var inputs = chunks.trim().split("\n");
    var number = inputs[0].split(" ")[0].split("");
    var ks = inputs[1].split(" ").map((k) => parseInt(k, 10));
    var ans = [];

    var carry = false;
    for (i = number.length - 1; i >= 0; i--) {
      var n = parseInt(number[i], 10);
      if (carry) {
        n = n + 1;
        if (n >= 10) {
          n = 10 - n;
          carry = true;
        } else {
          carry = false;
        }
      }

      while (true) {
        if (ks.find((k) => k === n)) {
          n = n + 1;
          if (n >= 10) {
            n = 10 - n;
            carry = true;
          }
        } else {
          ans.unshift(n);
          break;
        }
      }
    }

    if (carry) {
      ans.unshift(1);
    }

    console.log(ans);
  });
}

main();
//  [go]
package main

import "fmt"

func main() {
	var N, K int
	fmt.Scan(&N, &K)
	D := make([]bool, 10)
	for i := 0; i < K; i++ {
		var t int
		fmt.Scan(&t)
		D[t] = true
	}
	// fmt.Println("N", N, "K", K, "D", D)
	for v := N; v <= 1000000; v++ {
		ok := true
		t := v
		for t > 0 {
			if D[t%10] {
				ok = false
				break
			} else {
				t /= 10
			}
		}
		if ok {
			fmt.Println(v)
			return
		}
	}
}
//  [go]
package main

import (
	"fmt"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	d := make([]int, k)
	var e [10]bool
	var f []int
	for i := range d {
		fmt.Scan(&d[i])
		e[d[i]] = true
	}
	for i := 0; i < 10; i++ {
		if !e[i] {
			f = append(f, i)
		}
	}
	var x []int
	for n > 0 {
		x = append(x, n%10)
		n /= 10
	}
	p := len(x) - 1
	for p >= 0 {
		if e[x[p]] {
			break
		}
		p--
	}
	if p >= 0 {
		for {
			c := false
			j := x[p]
			for {
				j++
				if j == 10 {
					j = 0
					c = true
				}
				if !e[j] {
					break
				}
			}
			x[p] = j
			if !c {
				break
			}
			p++
			if p == len(x) {
				if f[0] == 0 {
					x = append(x, f[1])
				} else {
					x = append(x, f[0])
				}
				break
			}
		}
		for i := p - 1; i >= 0; i-- {
			x[i] = f[0]
		}
	}
	for i := len(x) - 1; i >= 0; i-- {
		fmt.Print(x[i])
	}
}
//  [go]
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	dm := make(map[int]bool)
	var d int
	for i := 0; i < k; i++ {
		fmt.Scan(&d)
		dm[d] = true
	}
	gs := make([]int, 0)
	for i := 0; i <= 9; i++ {
		if !dm[i] {
			gs = append(gs, i)
		}
	}

	u := 0
	nums := make([]int, 0)
	s := strconv.Itoa(n)
	for i := len(s) - 1; i >= 0; i-- {
		ok := false
		c := int(s[i]-'0') + u
		uu := 0
		if c >= 10 {
			c = 0
			uu = 1
		}
		for _, d := range gs {
			if c <= d {
				nums = append(nums, d)
				ok = true
				u = 0 + uu
				if c < d {
					nums = update(nums, gs)
				}

				break
			}
		}
		if !ok {
			nums = append(nums, gs[0])
			u = 1
			nums = update(nums, gs)
		}
	}

	if u > 0 {
		for _, g := range gs {
			if g > 0 {
				nums = append(nums, g)
				break
			}
		}
		nums = update(nums, gs)
	}

	for i := len(nums) - 1; i >= 0; i-- {
		fmt.Print(nums[i])
	}
	fmt.Println()
}

func update(nums, gs []int) []int {
	for j := 0; j < len(nums)-1; j++ {
		nums[j] = gs[0]
	}
	return nums
}
//  [go]
package main

import (
	"fmt"
	"strconv"
	"strings"
)

//文字列に変換し、嫌いな数字を使っていないかを判断する関数
func convertNum(slice []int, hateNum []int) int {
	//入力された金額を文字列に変換する
	var priceStr string
	priceStr = strconv.Itoa(slice[0])
	//入力された'嫌いな数字'を文字列のスライスに変換し、文字列型に変換
	hateNumStr := make([]string, slice[1])
	for i := 0; i < slice[1]; i++ {
		hateNumStr[i] = strconv.Itoa(hateNum[i])
	}

	count := 0 //嫌いな数字の個数をカウントする変数
	//値段と嫌いな数字が被っているかを確認(被っている：true,被っていない:false)
	//全て被っていなかったら1を返し、１つでも被りがある場合は-1を返す
	for i := 0; i < slice[1]; i++ {
		//fmt.Print()
		//fmt.Println(strings.Contains(priceStr, hateNumStr[i]))

		if strings.Contains(priceStr, hateNumStr[i]) == false {
			count++
			if count == slice[1] {
				return 1
			}
		}
	}
	return -1
}

func main() {
	//値段と嫌いな数字の個数を入れるためのスライスを生成する
	slice := make([]int, 2)

	//標準入力
	//fmt.Println("値段と嫌いな数字の個数を入力してください。")
	fmt.Scanln(&slice[0], &slice[1])

	//代入できているか確認
	//fmt.Printf("値段は%d円で, 嫌いな数字の個数は%d個です。\n", slice[0], slice[1])

	//嫌いな数字を入力する
	hateNum := make([]int, slice[1])
	//fmt.Println("嫌いな数字を入力してください")
	for i := 0; i < slice[1]; i++ {
		fmt.Scan(&hateNum[i])
	}

	//嫌いな数字の確認用
	//fmt.Printf("嫌いな数字は%dです\n", hateNum)

	minPrice := slice //値段からインクリメントさせるための変数
	judge := -1       //convetNumから返ってくる値を代入する（-1はダメ、1はOK

	//条件が10000までの値なので、それに合わせる
	for i := 0; i < 10000-slice[0]; i++ {
		judge = convertNum(minPrice, hateNum)
		if judge == 1 {
			fmt.Printf("%d", minPrice[0])
			break
		}
		minPrice[0]++
	}
}
//  [go]
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	var n, k int
	fmt.Scanf("%d %d", &n, &k)

	s := bufio.NewScanner(os.Stdin)
	s.Scan()
	split := strings.Split(s.Text(), " ")

	d := make([]int, k)
	for i, s := range split {
		d[i], _ = strconv.Atoi(s)
	}

	base := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
	fav := make([]int, 0, len(base)-k)
l1:
	for _, b := range base {
		for _, v := range d {
			if b == v {
				continue l1
			}
		}
		fav = append(fav, b)
	}

l2:
	for i := n; i < 10000; i++ {
		var ns []int
		ns = digit(i, ns)

		for j := 0; j < len(ns); j++ {
			var valid bool
			for _, v := range fav {
				if ns[j] == v {
					valid = true
				}
			}
			if !valid {
				continue l2
			}
		}

		fmt.Printf("%d", i)
		break
	}
}

func digit(i int, list []int) []int {
	if i > 0 {
		return digit(i/10, append(list, i%10))
	}
	return list
}