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