import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.exception;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int [] get (string s)
{
	auto f = new int [10];
	foreach (c; s)
	{
		f[c - '0']++;
	}
	f[2] += f[5];
	f[5] = 0;
	f[6] += f[9];
	f[9] = 0;
	return f;
}

void main ()
{
	string s;
	while ((s = readln ().strip ()) != null)
	{
		string t = readln ().strip ();
		auto f = get (s);
		auto g = get (t);
		int res = int.max;
		foreach (i; 0..10)
		{
			if (f[i] > 0)
			{
				res = min (res, g[i] / f[i]);
			}
		}
		writeln (res);
	}
}
