#include <bits/stdc++.h>
using namespace std;
const double pi = 3.14159265358979323;
const double eps = 1e-8;
const int inf = 1 << 29;
int a, b, cnt, s[100];
int c[1000000];
bool check(int x) {
  int tot = 0;
  while (x) {
    if (x % 10 == 4 || x % 10 == 7) c[tot++] = x % 10;
    x /= 10;
  }
  if (cnt != tot) return false;
  for (int i = 0; i < tot; i++) {
    if (s[i] != c[i]) return false;
  }
  return true;
}
int main() {
  {
    cin >> a >> b;
    int tmp = b;
    cnt = 0;
    while (tmp) {
      s[cnt++] = tmp % 10;
      tmp /= 10;
    }
    int ans = a + 1;
    while (1) {
      if (check(ans)) break;
      ans++;
    }
    cout << ans << endl;
  }
  return 0;
}
