#include <bits/stdc++.h>
using namespace std;
signed main(void) {
  long long n, m;
  cin >> n >> m;
  vector<long long> second(n), T(m);
  for (long long i = 0; i < n; i++) cin >> second[i];
  for (long long i = 0; i < m; i++) cin >> T[i];
  vector<vector<long long>> dp(n + 1, vector<long long>(m + 1, 1));
  for (long long i = 0; i < n; i++)
    for (long long j = 0; j < m; j++) {
      if (second[i] == T[j])
        dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1]) % 1000000007;
      else
        dp[i + 1][j + 1] =
            (dp[i + 1][j] + dp[i][j + 1] - dp[i][j]) % 1000000007;
    }
  cout << dp[n][m] << endl;
}
