#include <bits/stdc++.h>
using namespace std;
int a[11], b[11], ans = 1000000;
string s;
int main() {
  cin >> s;
  for (int i = 0; i < s.length(); i++) a[s[i] - 48]++;
  cin >> s;
  for (int i = 0; i < s.length(); i++) b[s[i] - 48]++;
  a[2] += a[5], b[2] += b[5], a[6] += a[9], b[6] += b[9];
  for (int i = 0; i <= 9; i++)
    if (a[i] > 0 && i != 5 && i != 9) ans = min(ans, b[i] / a[i]);
  cout << ans << endl;
  return 0;
}
