#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, s1;
  cin >> s >> s1;
  int freq1[10];
  int freq2[10];
  int freq3[10];
  for (int i = 0; i < 10; ++i) {
    freq1[i] = 0;
    freq2[i] = 0;
    freq3[i] = 0;
  }
  for (int i = 0; i < s.size(); ++i) freq1[(int)s[i] - 48]++;
  for (int i = 0; i < s1.size(); ++i) freq2[(int)s1[i] - 48]++;
  freq1[6] = freq1[6] + freq1[9];
  freq1[9] = 0;
  freq2[6] = freq2[6] + freq2[9];
  freq2[9] = 0;
  freq1[2] = freq1[2] + freq1[5];
  freq1[5] = 0;
  freq2[2] = freq2[2] + freq2[5];
  freq2[5] = 0;
  for (int i = 0; i < 10; ++i)
    if (freq1[i] && freq2[i]) freq3[i] = freq2[i] / freq1[i];
  sort(freq3, freq3 + 10);
  int t = 0;
  int ans;
  for (int i = 0; i < 10; ++i)
    if (freq3[i] && (!t)) {
      t = 1;
      ans = freq3[i];
    }
  if (t)
    cout << ans;
  else
    cout << 0;
  return 0;
}
