#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const long long mod = 1e9 + 7;
long long X[2048], Y[2048];
long long n, m;
void solve() {
  vector<vector<long long> > dp(n + 1, vector<long long>(m + 1, 1));
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
      if (X[i] == Y[j]) dp[i][j] += dp[i - 1][j - 1];
      dp[i][j] = (dp[i][j]) % mod;
    }
  }
  cout << dp[n][m] << "\n";
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) cin >> X[i];
  for (long long i = 1; i <= m; i++) cin >> Y[i];
  solve();
  return 0;
}
