#include <bits/stdc++.h>
using namespace std;
const long long INF = LLONG_MAX / 4;
const long long MOD = 1e9 + 7;
const int n_max = 1e5 + 10;
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> s(n);
  for (long long i = 0; i < (long long)(n); i++) cin >> s[i];
  vector<long long> t(m);
  for (long long i = 0; i < (long long)(m); i++) cin >> t[i];
  vector<vector<long long>> dp(n, vector<long long>(m, 0)),
      sum(n + 1, vector<long long>(m + 1, 0));
  for (long long i = 0; i < (long long)(n); i++) {
    for (long long j = 0; j < (long long)(m); j++) {
      if (s[i] != t[j])
        dp[i][j] = 0;
      else
        dp[i][j] = (sum[i][j] + 1) % MOD;
      sum[i + 1][j + 1] =
          (sum[i][j + 1] + sum[i + 1][j] - sum[i][j] + dp[i][j]) % MOD;
    }
  }
  cout << (sum[n][m] + 1) % MOD << endl;
}
