#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n, m;
  cin >> n >> m;
  long long s[2100];
  long long t[2100];
  for (long long i = 0; i < n; i++) cin >> s[i];
  for (long long i = 0; i < n; i++) cin >> t[i];
  long long ans = 1;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      long long memo = 0;
      if (s[i] == t[j]) {
        memo++;
        long long k = j + 1;
        long long l = i + 1;
        while (1) {
          if (t[k] == s[l]) {
            memo++;
            k++;
            l++;
          } else {
            k = i + 2;
            l = j + 2;
          }
          if (k >= n || l >= m) break;
        }
      }
      ans += memo;
    }
  }
  cout << ans << endl;
  return 0;
}
