#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  while (t--) {
    int a, b, c;
    string s;
    vector<int> v;
    vector<int> req;
    vector<int> ans;
    int freq_1[201] = {0};
    int freq_2[2001] = {0};
    cin >> a;
    cin >> s;
    while (a > 0) {
      req.push_back(a % 10);
      a /= 10;
    }
    for (int i = 0; i < s.size(); i++) {
      v.push_back((s[i] - 48));
    }
    for (int i = 0; i < v.size(); i++) {
      freq_1[v[i]]++;
    }
    for (int i = 0; i < req.size(); i++) {
      freq_2[req[i]]++;
    }
    freq_2[2] += freq_2[5];
    freq_2[5] = freq_2[2];
    freq_2[6] += freq_2[9];
    freq_2[9] = freq_2[6];
    b = freq_2[2];
    c = freq_2[6];
    freq_1[2] += freq_1[5];
    freq_1[5] = freq_1[2];
    freq_1[6] += freq_1[9];
    freq_1[9] = freq_1[6];
    for (int i = 0; i < req.size(); i++) {
      if (req[i] == 2 || req[i] == 5) {
        if (b > 0) {
          ans.push_back(freq_1[req[i]] / b);
        }
      } else if (req[i] == 6 || req[i] == 9) {
        if (c > 0) {
          ans.push_back(freq_1[req[i]] / c);
        }
      } else
        ans.push_back(freq_1[req[i]] / freq_2[req[i]]);
    }
    sort(ans.begin(), ans.end());
    cout << ans[0];
  }
  return 0;
}
