#include <bits/stdc++.h>
using namespace std;
long long Calculation(int y, int m, int d) {
  if (m < 3) {
    y -= 1;
    m += 12;
  }
  return 365 * y + y / 4 - y / 100 + y / 400 + (153 * m - 457) / 5 + d - 306;
}
bool cmp(int a, int b) { return a > b; }
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
inline string r(string n) {
  string k = "";
  for (int i = n.size() - 1; i >= 0; i--) k += n[i];
  return k;
}
int main() {
  int ans[10] = {0}, a1[10] = {0};
  string s1, s2;
  int i, j, n, t;
  cin >> s1 >> s2;
  for (i = 0; i < s1.length(); i++) {
    int x = s1[i] - '0';
    ans[x]++;
  }
  for (i = 0; i < s2.length(); i++) {
    int y = s2[i] - '0';
    a1[y]++;
  }
  int ansx = 0x3f3f3f3f, f1 = 0, f2 = 0;
  for (i = 0; i <= 9; i++) {
    if (ans[i] == 0) {
      continue;
    } else {
      if (i == 6 || i == 9 || i == 2 || i == 5) {
        if (i == 6 || i == 9 && f1 == 0) {
          f1 = 1;
          int d2;
          d2 = (a1[6] + a1[9]) / (ans[6] + ans[9]);
          ansx = min(ansx, d2);
        } else if (i == 2 || i == 5 && f2 == 0) {
          f2 = 1;
          int d3;
          d3 = (a1[2] + a1[5]) / (ans[2] + ans[5]);
          ansx = min(ansx, d3);
        }
        continue;
      }
      if (ans[i] > a1[i]) {
        cout << 0 << endl;
        return 0;
      } else {
        int d1 = a1[i] / ans[i];
        ansx = min(ansx, d1);
      }
    }
  }
  cout << ansx << endl;
}
