#include <bits/stdc++.h>
using namespace std;
const double EPS = 10e-6;
const int INF = 1000000000;
const int LIMIT = 100;
const int BUFFER_SIZE = 1 * 1024;
char buffer[BUFFER_SIZE];
char* read_line() {
  int ch, size = 0;
  while ((ch = getchar()) != '\n') buffer[size++] = ch;
  buffer[size] = '\0';
  return buffer;
}
string mask(int n) {
  int len;
  string m = "";
  sprintf(buffer, "%d", n);
  len = strlen(buffer);
  for (int i = 0; i < len; i++)
    if (buffer[i] == '4' || buffer[i] == '7') m += buffer[i];
  return m;
}
int main(int argc, char* argv[]) {
  int a, b;
  cin >> a >> b;
  string temp = mask(b);
  for (int c = a + 1;; c++) {
    if (mask(c) == temp) {
      cout << c << endl;
      break;
    }
  }
  return EXIT_SUCCESS;
}
