#include <bits/stdc++.h>
using namespace std;
using lint = long long;
int main(void) {
  int N, M;
  cin >> N >> M;
  vector<lint> S(N);
  vector<lint> T(M);
  for (auto& x : S) {
    cin >> x;
  }
  for (auto& x : T) {
    cin >> x;
  }
  int sum = 1;
  for (int i = 0; i < N; i++) {
    int cnt = 0;
    int sub = i;
    for (int j = i; j < N; j++) {
      if (S[i - sub] == S[j]) {
        cnt++;
      } else {
        sum += cnt * cnt - 1;
        sub = j;
        cnt = 0;
      }
    }
  }
  cout << sum << endl;
  return 0;
}
