#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> S, T;
  for (int i = (0); i < (N); ++i) {
    int s;
    cin >> s;
    S.push_back(s);
  }
  for (int i = (0); i < (M); ++i) {
    int t;
    cin >> t;
    T.push_back(t);
  }
  vector<vector<long long> > dp, sum;
  dp.push_back(vector<long long>(M + 1, 1));
  for (int i = (0); i < (N); ++i) {
    vector<long long> v(M + 1, 0);
    vector<long long> s(M + 1, 0);
    v[0] = 1;
    dp.push_back(v);
    sum.push_back(s);
  }
  for (int s = (0); s < (N); ++s) {
    for (int t = (0); t < (M); ++t) {
      dp[s + 1][t + 1] = dp[s][t + 1] + dp[s + 1][t];
      dp[s + 1][t + 1] %= (long long)1e9 + 7;
      if (S[s] != T[t]) {
        dp[s + 1][t + 1] += (long long)1e9 + 7 - dp[s][t];
      }
    }
  }
  cout << dp[N][M] << endl;
  return 0;
}
