#include <bits/stdc++.h>
using namespace std;
int get(int n) {
  int re = 0;
  int t = 1;
  while (n > 0) {
    int tt = n % 10;
    if (tt == 4 || tt == 7) {
      re = re + tt * t;
      t *= 10;
    }
    n = n / 10;
  }
  return re;
}
int main() {
  int a, b;
  while (cin >> a >> b) {
    for (int i = a + 1;; i++)
      if (b == get(i)) {
        cout << i << "\n";
        break;
      }
  }
  return 0;
}
