#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  if (b > a) {
    cout << b;
    return 0;
  }
  int i, k, s;
  s = 1;
  while (s <= a) s *= 10;
  s /= 10;
  int c = a;
  while (true) {
    k = 0;
    bool f = 0;
    for (i = s; i >= 1; i /= 10) {
      int t = (c / i) % 10;
      if (t == 4 || t == 7) {
        if (f) {
          k = k * 10 + t;
        } else {
          f = 1;
          k = t;
        }
      }
    }
    if (k == b && c > a) {
      cout << c;
      break;
    } else
      c++;
  }
  return 0;
}
