#include <bits/stdc++.h>
using namespace std;
string zr, st;
long ttl[1000], need[1000], ans;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> zr;
  cin >> st;
  for (int i = 0; i < st.size(); i++) {
    ttl[st[i]]++;
  }
  ttl['2'] += ttl['5'];
  ttl['6'] += ttl['9'];
  ans = 0;
  for (int i = 0; i < zr.size(); i++) {
    if (zr[i] == '5')
      need['2']++;
    else if (zr[i] == '9')
      need['6']++;
    else
      need[zr[i]]++;
  }
  ans = 1000000;
  for (int i = '0'; i <= '9'; i++)
    if (need[i] > 0) ans = min(ans, ttl[i] / need[i]);
  cout << ans << endl;
  cin.get();
  cin.get();
  return 0;
}
