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