#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 2e9;
const long long INF64 = 9e18;
const long double EPS = 1e-12;
const long double PI =
    3.14159265358979323846264338327950288419716939937510582097;
const long long MD = 835355424;
const long long T = 634521;
const int N = 100100;
const int M = 1001;
int a, b;
bool get(int first) {
  int z = 0;
  int t = 1;
  while (first > 0) {
    int zz = first % 10;
    first /= 10;
    if (zz != 4 && zz != 7) continue;
    z += t * zz;
    t *= 10;
  }
  return (z == b);
}
int main() {
  cin >> a >> b;
  for (int i = a + 1; i < 9999999; i++)
    if (get(i)) {
      cout << i;
      return 0;
    }
  return 0;
}
