#include <bits/stdc++.h>
using namespace std;
using namespace std;
int mask(int x) {
  int ret = 0, m = 1;
  while (x) {
    int d = x % 10;
    x /= 10;
    if (d == 4 || d == 7) {
      ret += d * m;
      m *= 10;
    }
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int a, b;
  cin >> a >> b;
  while (true) {
    a++;
    if (mask(a) == b) return cout << a << endl, 0;
  }
  return 0;
}
