#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2")
#pragma GCC optimize("trapv")
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cout << *it << " : " << a << endl;
  err(++it, args...);
}
long long int gcd(long long int a, long long int b) {
  while (b) {
    long long int c = b;
    b = a % b;
    a = c;
  }
  return a;
}
long long int lcm(long long int a, long long int b) {
  if (!a || !b) return 0;
  return a * b / gcd(a, b);
}
int main() {
  int foo;
  cin >> foo;
  int aux = foo;
  map<int, int> go;
  while (aux > 0) {
    int di = aux % 10;
    aux /= 10;
    if (di == 5)
      go[2]++;
    else if (di == 9)
      go[6]++;
    else
      go[di]++;
  }
  string s;
  cin >> s;
  map<int, int> m;
  for (long long int i = 0; i < ((s).size()); ++i) {
    int num = s[i] - '0';
    if (num == 5)
      m[2]++;
    else if (num == 9)
      m[6]++;
    else
      m[num]++;
  }
  int mini = 1e9;
  for (auto x : go) {
    int nume = x.first, ocur = x.second;
    mini = min(mini, m[nume] / ocur);
  }
  cout << mini << endl;
  return 0;
}
