#include <bits/stdc++.h>
using namespace std;
void solve() {
  string n, s;
  cin >> n >> s;
  map<int, int> mp, mp2;
  int mn = INT_MAX;
  for (int i = 0; i < n.length(); i++) {
    if (n[i] == '2' || n[i] == '5')
      mp[2]++;
    else if (n[i] == '6' || n[i] == '9')
      mp[6]++;
    else
      mp[n[i] - '0']++;
  }
  n = s;
  for (int i = 0; i < n.length(); i++) {
    if (n[i] == '2' || n[i] == '5')
      mp2[2]++;
    else if (n[i] == '6' || n[i] == '9')
      mp2[6]++;
    else
      mp2[n[i] - '0']++;
  }
  for (auto it : mp) {
    if (mp2.find(it.first) == mp2.end()) {
      cout << "0\n";
      return;
    } else
      mn = min(mn, mp2[it.first] / it.second);
  }
  cout << mn << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int T = 1;
  while (T--) {
    solve();
  }
}
