#include <bits/stdc++.h>
using namespace std;
const int MAX = 100000 + 10;
const int Alpha = 27;
string str;
int sum[Alpha], need[Alpha];
int get(char a) {
  if (a == '9') a = '6';
  if (a == '5') a = '2';
  return a - '0';
}
int main() {
  int i;
  cin >> str;
  for ((i) = (0); (i) != ((int)str.size()); ++(i)) ++need[get(str[i])];
  cin >> str;
  for ((i) = (0); (i) != ((int)str.size()); ++(i)) ++sum[get(str[i])];
  int ans = 1000000000;
  for ((i) = (0); (i) != (Alpha); ++(i))
    if (!sum[i] && need[i])
      ans = 0;
    else if (need[i])
      ans = min(ans, sum[i] / need[i]);
  cout << ans << endl;
  return 0;
}
