#include <bits/stdc++.h>
using namespace std;
int decimalRep(long long x) {
  int ans = 0;
  while (x) {
    if (x % 10 == 7 || x % 10 == 4) ans = ans * 10 + x % 10;
    x /= 10;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long a, b;
  cin >> a >> b;
  do {
    a++;
  } while (decimalRep(a) != decimalRep(b));
  cout << a << '\n';
  return 0;
}
