#include <bits/stdc++.h>
using namespace std;
struct abc {
  int x;
  int win;
} s;
int main() {
  int n, k, i, coun = 0, j, x[11] = {0}, y[11] = {0};
  string t;
  cin >> t;
  for (i = 0; i < t.length(); i++) {
    if (t[i] == '5') t.replace(i, 1, "2");
    if (t[i] == '9') t.replace(i, 1, "6");
    x[t[i] - '0']++;
  }
  string a;
  cin >> a;
  for (j = a.length() - 1; j >= 0; j--) {
    if (a[j] == '5') a.replace(j, 1, "2");
    if (a[j] == '9') a.replace(j, 1, "6");
    y[a[j] - '0']++;
  }
  int min = 10000000;
  for (i = 0; i < 10; i++) {
    if (x[i] && y[i] / x[i] < min) min = y[i] / x[i];
  }
  cout << min << endl;
  return 0;
}
