#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int main() {
  string n;
  cin >> n;
  string s;
  cin >> s;
  int a[10] = {0};
  int b[10] = {0};
  for (int i = 0; i < n.length(); i++) ++a[n[i] - '0'];
  for (int i = 0; i < s.length(); i++) ++b[s[i] - '0'];
  int an = 0;
  b[6] += b[9];
  b[2] += b[5];
  b[9] = b[6];
  b[5] = b[2];
  while (1) {
    int i;
    for (i = 0; i < 10; i++) {
      if (b[i] >= a[i]) {
        if (i != 6 && i != 9 && i != 2 && i != 5)
          b[i] -= a[i];
        else {
          b[i] -= a[i];
          if (i == 9 || i == 5)
            b[i - 3] -= a[i];
          else
            b[i + 3] -= a[i];
        }
      } else
        break;
    }
    if (i == 10)
      ++an;
    else
      break;
  }
  cout << an << endl;
}
