#include <bits/stdc++.h>
using namespace std;
long long digcount(long long x) {
  long long temp = 1, ans = 0;
  while (x > 0) {
    long long f = x % 10;
    x /= 10;
    if (f == 4 or f == 7) {
      ans += f * temp;
      temp *= 10;
    }
  }
  return ans;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long a, b;
  cin >> a >> b;
  if (b > a) {
    cout << b << endl;
    return 0;
  }
  for (long long i = a + 1;; i++) {
    if (digcount(i) == b) {
      cout << i << endl;
      return 0;
    }
  }
}
