#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  cout.tie(0);
  int p[11], q[11], minimo = 10000;
  string s, t;
  for (int i = 0; i < 11; i++) {
    p[i] = 0;
    q[i] = 0;
  }
  cin >> s >> t;
  for (int i = 0; i < s.length(); i++)
    if (s[i] == '5')
      p[2]++;
    else if (s[i] == '9')
      p[6]++;
    else
      p[s[i] - '0']++;
  for (int i = 0; i < t.length(); i++)
    if (t[i] == '5')
      q[2]++;
    else if (t[i] == '9')
      q[6]++;
    else
      q[t[i] - '0']++;
  for (int i = 0; i < 8; i++)
    if ((i != 5) && (p[i] != 0)) minimo = min(minimo, q[i] / p[i]);
  cout << minimo;
  return 0;
}
