#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, i, j, ans = 0;
  string s = " ";
  vector<int> v1;
  vector<int> v2;
  cin >> t;
  cin >> s;
  for (i = 0; i < 10; i++) {
    v1.push_back(0);
    v2.push_back(0);
  }
  while (t) {
    i = t % 10;
    t = t / 10;
    if (i == 2 || i == 5) {
      v1[2]++;
    } else if (i == 6 || i == 9) {
      v1[6]++;
    } else
      v1[i]++;
  }
  j = 0;
  while (j < s.size()) {
    i = s[j] - '0';
    if (i == 2 || i == 5) {
      v2[2]++;
    } else if (i == 6 || i == 9) {
      v2[6]++;
    } else
      v2[i]++;
    j++;
  }
  ans = 1000000;
  for (i = 0; i < 10; i++) {
    if (v1[i] != 0) {
      ans = min<int>(ans, v2[i] / v1[i]);
    }
  }
  cout << ans << endl;
  return 0;
}
