// Arup Guha
// 1/28/2021
// Solution to 2021 USACO January Bronze Problem: Uddered but not Herd

import java.util.*;

public class uddered {

	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		String alpha = stdin.next();
		
		// rank[i] will store what rank letter i is in this cowalphabet.
		int[] rank = new int[26];
		
		// Just map each letter to its rank, so if 'g' is first, then rank[6] = 0, since 6
		// stands for g, and it comes in 0th place.
		for (int i=0; i<alpha.length(); i++)
			rank[alpha.charAt(i)-'a'] = i;
		
		// Get the udderance...
		String phrase = stdin.next();
		
		int res = 0, curRank = 26;
		for (int i=0; i<phrase.length(); i++) {
		
			// What rank this letter has in the cowalphabet.
			int newRank = rank[phrase.charAt(i)-'a'];
			
			// Move to the next alphabet string.
			if (newRank <= curRank) res++;
			
			// Update the current rank.
			curRank = newRank;
		}
		
		// Ta da!
		System.out.println(res);		
	}
}