//
// Written by Fyodor Menshikov 27.02.2008
// 23:49-24:02
// Debugged 01.03.2008 12:30-12:46
//

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

class Main {

   Scanner in;
   PrintWriter out;

   Main() {
      try {
         in = new Scanner(System.in);
         out = new PrintWriter(System.out);
      } catch (Exception e) {
         throw new Error();
      }
   }

   void asserT(boolean e) {
      if (!e) {
         throw new Error();
      }
   }

   void run() {
      String s1 = in.nextLine();
      String s2 = in.nextLine();
      asserT(s1.length() > 0);
      asserT(s2.length() > 0);
      int suff[] = new int[s2.length()];
      suff[0] = 0;
      int j = 0;
      for (int i = 1; i < s2.length(); i++) {
         while (true) {
            if (s2.charAt(i) == s2.charAt(j)) {
               j++;
               break;
            }
            if (j == 0) {
               break;
            }
            j = suff[j - 1];
         }
         suff[i] = j;
      }
      j = 0;
      for (int i = 0; i < s1.length(); i++) {
         while (true) {
            if (s1.charAt(i) == s2.charAt(j)) {
               j++;
               break;
            }
            if (j == 0) {
               break;
            }
            j = suff[j - 1];
         }
      }
      out.println(j);
      out.close();
   }

   public static void main(String args[]) {
      new Main().run();
   }
}