#include <bits/stdc++.h>
using namespace std;
int getm(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 a, c, b;
  cin >> a >> b;
  c = a + 1;
  while (getm(c) != b) c++;
  cout << c;
  return 0;
}
