#include <bits/stdc++.h>
using namespace std;
int f(int x) {
  int ans = 0;
  vector<int> v;
  for (; x > 0; x /= 10)
    if (x % 10 == 4 || x % 10 == 7) v.push_back(x % 10);
  reverse(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++) (ans += v[i]) *= 10;
  ans /= 10;
  return ans;
}
int main() {
  int a, b;
  cin >> a >> b;
  int x = a;
  while (1) {
    if (f(x) == b && x > a) break;
    x++;
  }
  cout << x;
  return 0;
}
