#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000009;
void solve() {
  long long n, m;
  cin >> n >> m;
  long long s[n + 10];
  long long t[m + 10];
  for (long long i = 0; i < n; i++) {
    cin >> s[i + 1];
  }
  for (long long i = 0; i < m; i++) {
    cin >> t[i + 1];
  }
  long long dp[n + 10][m + 10];
  long long sum[n + 10][m + 10];
  for (long long i = 0; i < n + 1; i++) {
    dp[i][0] = 0;
    sum[i][0] = 0;
    sum[i][m] = 0;
  }
  for (long long i = 0; i < m + 1; i++) {
    dp[0][i] = 0;
    sum[0][i] = 0;
    sum[n][i] = 0;
  }
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      if (s[i] == t[j])
        dp[i][j] = (sum[i - 1][j - 1] + 1) % MOD;
      else
        dp[i][j] = 0;
      sum[i][j] =
          (sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + dp[i][j]) % MOD;
    }
  }
  long long ans = 0;
  for (long long i = 0; i < n + 1; i++) {
    for (long long j = 0; j < m + 1; j++) {
      ans = (ans + dp[i][j]) % MOD;
    }
  }
  cout << ans + 1 << endl;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
