#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
int main() {
  int N, M, t;
  long long mod = 1e9 + 7;
  cin >> N >> M;
  vector<int> vs(N), vt(M);
  vector<vector<int> > a(N, vector<int>(M, 0));
  for (int i = 0; i < N; i++) {
    cin >> vs[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> t;
    vt[i] = t;
    for (int j = 0; j < N; j++) {
      if (vs[j] == t) {
        a[j][i] = 1;
      }
    }
  }
  long long ans = 1;
  vector<vector<long long> > dp(N + 1, vector<long long>(M + 1, 0));
  vector<vector<long long> > sum(N + 1, vector<long long>(M + 1, 0));
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < M; ++j) {
      if (a[i][j] == 0)
        dp[i + 1][j + 1] = 0;
      else
        dp[i + 1][j + 1] = (sum[i][j] + 1) % mod;
      ans += dp[i + 1][j + 1];
      sum[i + 1][j + 1] =
          (sum[i + 1][j] + sum[i][j + 1] - sum[i][j] + dp[i + 1][j + 1]) % mod;
      ans %= mod;
    }
  }
  cout << ans << endl;
}
