#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b;
  cin >> a >> b;
  for (int i = a + 1;; i++) {
    int x = i;
    vector<int> q;
    while (x) {
      q.push_back(x % 10);
      x /= 10;
    }
    reverse(q.begin(), q.end());
    long long cur = 0;
    for (int i = 0; i < q.size(); i++)
      if (q[i] == 4 || q[i] == 7) cur = cur * 10 + q[i];
    if (cur == b) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}
