#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, b;
  cin >> a >> b;
  vector<int> c, d;
  int flag = 0;
  vector<int> e(10, 0), f(10, 0);
  for (int i = 0; a[i] != '\0'; i++) {
    c.push_back((a[i]) - 48);
    e[c[i]]++;
  }
  for (int i = 0; b[i] != '\0'; i++) {
    d.push_back((b[i]) - 48);
    f[d[i]]++;
  }
  int mi = INT_MAX, dig;
  for (int i = 0; i < 10; i++) {
    if (i != 2 && i != 5 && i != 6 && i != 9) {
      if (e[i] > f[i]) flag = 1;
      if (e[i] > 0) {
        f[i] /= e[i];
      }
    }
  }
  if (flag) {
    cout << "0";
    return 0;
  } else {
    e[2] += e[5];
    e[5] = e[2];
    e[6] += e[9];
    e[9] = e[6];
    f[2] += f[5];
    f[6] += f[9];
    if (e[2] > 0) f[2] /= e[2];
    if (e[6] > 0) f[6] /= e[6];
    f[5] = f[2];
    f[9] = f[6];
    for (int i = 0; i < 10; i++) {
      if (e[i] > 0 && f[i] < mi) {
        mi = f[i];
      }
    }
    cout << mi;
  }
  return 0;
}
