#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> a(n, 0), b(m, 0);
  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 + 1, vector<long long>(m + 1, 1));
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      if (a[i - 1] == b[j - 1]) {
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
      } else {
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1] + dp[i - 1][j - 1];
      }
      dp[i][j] %= 1000000007;
    }
  }
  cout << dp[n][m] << endl;
  return 0;
}
