#include <bits/stdc++.h>
using namespace std;
int mask2(int x) {
  int m = 0;
  while (x > 0) {
    int y = x % 10;
    if (y == 4 || y == 7) m = m * 10 + y;
    x /= 10;
  }
  return m;
}
int main() {
  int a, b, c, cnt = 0;
  cin >> a >> b;
  int mask = 0;
  c = b;
  while (c > 0) {
    int x = c % 10;
    if (x == 4 || x == 7) mask = mask * 10 + x;
    c /= 10;
  }
  for (int i = a + 1;; ++i) {
    if (mask2(i) == mask) {
      cout << i;
      break;
    }
  }
  return 0;
}
