#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  long long int mod = 1000000007;
  int n, m;
  cin >> n >> m;
  int s[n];
  int t[m];
  int res[m];
  for (int i = 0; i < m; ++i) {
    res[i] = 0;
  }
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }
  for (int i = 0; i < m; ++i) {
    cin >> t[i];
  }
  for (int i = 0; i < n; ++i) {
    int a = s[i];
    int sum = 0;
    for (int j = 0; j < m; ++j) {
      int b = res[j];
      if (t[j] == a) {
        res[j] += 1 + sum;
      }
      sum += b;
    }
  }
  int ans = 0;
  for (int i = 0; i < m; i++) {
    ans += res[i];
  }
  cout << "ans = " << ans + 1 << endl;
  return 0;
}
