#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<char> pieces, puzzle;
  string X, Y;
  cin >> X >> Y;
  for (int i = 0; i < X.size(); i++) puzzle.push_back(X.at(i));
  for (int i = 0; i < Y.size(); i++) pieces.push_back(Y.at(i));
  sort(pieces.begin(), pieces.end());
  int count = 0, i = 0;
  while (true) {
    if (binary_search(pieces.begin(), pieces.end(), puzzle[i])) {
      pieces.erase(lower_bound(pieces.begin(), pieces.end(), puzzle[i]));
      i++;
    } else if (puzzle[i] == '6') {
      if (binary_search(pieces.begin(), pieces.end(), '9')) {
        pieces.erase(lower_bound(pieces.begin(), pieces.end(), '9'));
        i++;
      } else
        break;
    } else if (puzzle[i] == '9') {
      if (binary_search(pieces.begin(), pieces.end(), '6')) {
        pieces.erase(lower_bound(pieces.begin(), pieces.end(), '6'));
        i++;
      } else
        break;
    } else if (puzzle[i] == '2') {
      if (binary_search(pieces.begin(), pieces.end(), '5')) {
        pieces.erase(lower_bound(pieces.begin(), pieces.end(), '5'));
        i++;
      } else
        break;
    } else if (puzzle[i] == '5') {
      if (binary_search(pieces.begin(), pieces.end(), '2')) {
        pieces.erase(lower_bound(pieces.begin(), pieces.end(), '2'));
        i++;
      } else
        break;
    } else {
      break;
    }
    if (i == puzzle.size()) {
      i = 0;
      count++;
    }
  }
  cout << count << endl;
  return 0;
}
