#include <bits/stdc++.h>
using namespace std;
ostream &operator<<(ostream &a, const vector<long long> &b) {
  for (auto k : b) cout << k << " ";
  return a;
}
const long long INF = 1e18;
const long long mod = 1e9 + 7;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  vector<long long> a(n), b(m);
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < m; i++) cin >> b[i];
  vector<vector<long long>> dp(n, vector<long long>(m, 0));
  if (a[0] == b[0]) dp[0][0] = 1;
  for (long long i = 1; i < n; i++) {
    dp[i][0] = dp[i - 1][0];
    if (a[i] == b[0]) dp[i][0] += 1;
  }
  for (long long i = 1; i < m; i++) {
    dp[0][i] = dp[0][i - 1];
    if (a[0] == b[i]) dp[0][i] += 1;
  }
  for (long long i = 1; i < n; i++) {
    for (long long j = 1; j < m; j++) {
      dp[i][j] = dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1];
      if (a[i] == b[j]) dp[i][j] += dp[i - 1][j - 1] + 1;
      dp[i][j] %= mod;
    }
  }
  cout << (dp[n - 1][m - 1] + 1) % mod;
}
