#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
void setup() {}
int main() {
  setup();
  long long T = 1;
  while (T--) {
    long long a, b;
    cin >> a >> b;
    long long ans = 0;
    a++;
    while (true) {
      string p = to_string(a);
      string mask = "";
      for (int i = 0; i < p.size(); i++) {
        if (p[i] == '4' or p[i] == '7') mask += p[i];
      }
      if (mask == to_string(b)) {
        ans = a;
        break;
      }
      a++;
    }
    cout << ans << endl;
  }
}
