#include <bits/stdc++.h>
using namespace std;
static const double EPS = 1e-6;
inline int ROUND(double x) { return (int)(x + 0.5); }
inline bool ISINT(double x) { return fabs(ROUND(x) - x) < EPS; }
inline bool ISEQUAL(double x, double y) {
  return fabs(x - y) <= EPS * max(fabs(x), fabs(y));
}
int main() {
  int a, b;
  cin >> a >> b;
  for (int c = a + 1;; c++) {
    int tmp = c;
    int d = 0;
    int base = 1;
    while (tmp) {
      if (tmp % 10 == 4 || tmp % 10 == 7) {
        d += (tmp % 10) * base;
        base *= 10;
      }
      tmp /= 10;
    }
    if (d == b) {
      cout << c << endl;
      return 0;
    }
  }
}
