#include <bits/stdc++.h>
using namespace std;
string n, str;
int a[15], b[15], minn = 100000;
int main() {
  cin >> n >> str;
  for (int i = 0; i <= n.length() - 1; i++) {
    if (n[i] == '5') {
      a[2]++;
      continue;
    }
    if (n[i] == '6') {
      a[9]++;
      continue;
    }
    a[n[i] - '0']++;
  }
  for (int i = 0; i <= str.length() - 1; i++) {
    if (str[i] == '5') {
      b[2]++;
      continue;
    }
    if (str[i] == '6') {
      b[9]++;
      continue;
    }
    b[str[i] - '0']++;
  }
  for (int i = 0; i <= 9; i++) {
    if (a[i] != 0) {
      if (minn > b[i] / a[i]) {
        minn = b[i] / a[i];
      }
    }
  }
  cout << minn;
  return 0;
}
