#include <bits/stdc++.h>
using namespace std;
void inc(string &a) {
  a[(int)a.size() - 1]++;
  int i = (int)a.size() - 1;
  while (a[i] > '9') {
    a[i] = '0';
    if (i != 0)
      a[--i]++;
    else {
      a += '0';
      for (int i = (int)a.size() - 1; i > 0; i--) a[i] = a[i - 1];
      a[0] = '1';
      return;
    }
  }
}
string mask(string &a) {
  string out = "";
  for (int i = 0; i < (int)a.size(); i++)
    if (a[i] == '4' || a[i] == '7') out += a[i];
  return out;
}
int main() {
  ios::sync_with_stdio(false);
  string a, b;
  cin >> a >> b;
  while (1) {
    inc(a);
    if (mask(a) == b) {
      cout << a << endl;
      return 0;
    }
  }
  return 0;
}
