#include <bits/stdc++.h>
int main() {
  int a, b, temp, t, sum, k;
  scanf("%d%d", &a, &b);
  while (1) {
    a++;
    temp = a;
    sum = 0;
    k = 1;
    while (temp != 0) {
      t = temp % 10;
      if (t == 4 || t == 7) {
        sum = sum + k * t;
        k *= 10;
      }
      temp = temp / 10;
    }
    if (sum == b) break;
  }
  printf("%d\n", a);
}
