#include <bits/stdc++.h>
using namespace std;
int dcmp(double x, double y) {
  return fabs(x - y) <= 1e-9 ? 0 : x < y ? -1 : 1;
}
string b;
int get_mask(int a) {
  string ret;
  while (a > 0) {
    if (a % 10 == 7)
      ret += (7 + '0');
    else if (a % 10 == 4)
      ret += (4 + '0');
    a /= 10;
  }
  reverse(((ret).begin()), ((ret).end()));
  return ret == b;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int a;
  cin >> a >> b;
  for (int i = a + 1; i <= 1e7; i++) {
    if (get_mask(i)) {
      cout << i << '\n';
      break;
    }
  }
}
