import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
String searchword = s.next();
String targetword = s.next();
int res = mininsertions(searchword,targetword);
System.out.println(res);
}
public static int mininsertions(String searchword,String targetword){
int n = searchword.length(), m = targetword.length();
int i=0,j=0;
//Loop to check how many characters of targetword matches with searchword.
//Number of Characters that don't match are the actual number of insertions needed at searchWord.
while(i<n && j<m){
if(searchword.charAt(i)==targetword.charAt(j))
++j;
++i;
}
return m - j;
}
}