#include <bits/stdc++.h>
using namespace std;
const long long int LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(N), t(M);
  for (int i = 0; i < (N); ++i) {
    cin >> s[i];
  }
  for (int i = 0; i < (M); ++i) {
    cin >> t[i];
  }
  vector<vector<long long int> > sum(N, vector<long long int>(M, 0));
  for (int i = (N)-1; i >= 0; --i) {
    for (int j = (M)-1; j >= 0; --j) {
      if (j + 1 < M && i + 1 < N) {
        sum[i][j] = sum[i + 1][j] + sum[i][j + 1] - sum[i + 1][j + 1];
      } else if (j + 1 < M) {
        sum[i][j] = sum[i][j + 1];
      } else if (i + 1 < N) {
        sum[i][j] = sum[i + 1][j];
      }
      sum[i][j] %= MOD;
      if (s[i] != t[j]) continue;
      long long int k = 1;
      if (j + 1 < M && i + 1 < N) {
        k += sum[i + 1][j + 1];
      }
      sum[i][j] += k;
      sum[i][j] %= MOD;
    }
  }
  cout << (sum[0][0] + 1) % MOD << endl;
  return 0;
}
