#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  return b == 0 ? a : gcd(b, a % b);
}
const long long int mod = 1000000007;
int main() {
  int N, M;
  cin >> N >> M;
  vector<long long int> S(N), T(M);
  for (int i = 0; i < (N); ++i) {
    cin >> S[i];
  }
  for (int j = 0; j < (M); ++j) {
    cin >> T[j];
  }
  vector<long long int> res(N);
  for (int i = 0; i < (N); ++i) {
    long long int tempSum = 0;
    for (int j = 0; j < (M); ++j) {
      long long int buf = res[j];
      if (S[i] == T[j]) {
        res[j] = (res[j] + 1 + tempSum) % mod;
      }
      tempSum = (tempSum + buf) % mod;
    }
  }
  long long int ans = 1;
  for (int i = 0; i < (M); ++i) {
    ans = (ans + res[i]) % mod;
  }
  cout << ans << endl;
  return 0;
}
