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