def search(s_iti,t_iti_list,n,memo3,memo1,s):
     if s_iti==n-1:
          return 0
     else:
          tmp=memo3[memo1.index(s[s_iti+1])]
          tmp2=[]
          for i in tmp:
               if i-1 in t_iti_list:
                    tmp2.append(i)
          return search(s_iti+1,tmp2,n,memo3,memo1,s)+len(tmp2)
def main():
     n,m=map(int,input().split())
     s=list(map(int,input().split()))
     t=list(map(int,input().split()))
     memo1=[]#si
     memo2=[]#siとなるsiの位置
     memo3=[]#siとなるtiの位置
     for i in range(n):
          if s[i] not in memo1:
               memo2.append([i])
               memo1.append(s[i])
               tmp_ti=[]
               for j in range(m):
                    if t[j]==s[i]:
                         tmp_ti.append(j)
               memo3.append(tmp_ti)
          else:
               memo2[memo1.index(s[i])].append(i)
     cnt=0
     for i in range(len(memo1)):
          cnt+=len(memo2[i])*len(memo3[i])
          for j in memo2[i]:
               cnt+=search(j,memo3[i],n,memo3,memo1,s)
     print(cnt+1)
                    
     
     
if __name__=='__main__':
     main()
