#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, b;
  int i, j, ans = 1000000, s1[10] = {0}, s2[10] = {0};
  cin >> a;
  for (i = 0; i < a.size(); i++) {
    s1[a[i] - '0']++;
  }
  cin >> b;
  for (i = 0; i < b.size(); i++) {
    s2[b[i] - '0']++;
  }
  s1[6] += s1[9];
  s1[2] += s1[5];
  s2[6] += s2[9];
  s2[2] += s2[5];
  for (i = 0; i <= 9; i++) {
    if (i == 9 || i == 5) continue;
    if (s1[i] > 0) ans = min(ans, s2[i] / s1[i]);
  }
  cout << ans << endl;
  return 0;
}
