#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, a[10] = {0}, b[10] = {0}, sum = 0;
  string s;
  cin >> t >> s;
  while (t > 0) {
    a[t % 10]++;
    t /= 10;
  }
  a[2] += a[5];
  a[5] = 0;
  a[6] += a[9];
  a[9] = 0;
  for (int i = 0; i < s.size(); i++) b[s[i] - '0']++;
  b[2] += b[5];
  b[5] = 0;
  b[6] += b[9];
  b[9] = 0;
  int ans = 99999;
  for (int i = 0; i < 9; i++)
    if (a[i] && b[i]) ans = min(ans, b[i] / a[i]);
  cout << ans << endl;
  return 0;
}
