/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	public static int sol(String s,String t){
		int count = Integer.MAX_VALUE;
		int smp[] = new int[26];
		int tmp[] = new int[26];
		for(int i=0;i<s.length();i++){
			smp[s.charAt(i)-'a']++;
		}
		for(int i=0;i<t.length();i++){
			tmp[t.charAt(i)-'a']++;
		}
		for(char c:t.toCharArray()){
			if(smp[c-'a']==0) return 0;
			count=Math.min(count,smp[c-'a']/tmp[c-'a']);
		}
		return count;
		
	}
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		System.out.println(sol(s,t));
	}
}