#include <bits/stdc++.h>
using namespace std;
const long long MAX_V = 100000;
const long long INF = 1e9;
const long long MOD = 1e9 + 7;
int main() {
  int N, M;
  cin >> N >> M;
  vector<long long> S(N + 1), T(M + 1);
  for (int i = 0; i < (int)(N); ++i) cin >> S[i];
  for (int i = 0; i < (int)(M); ++i) cin >> T[i];
  vector<vector<long long> > dp(N + 1, vector<long long>(M + 1, 0));
  for (int i = (int)(1); i < (int)(N + 1); ++i) {
    for (int j = (int)(1); j < (int)(M + 1); ++j) {
      if (T[j - 1] == S[i - 1]) {
        dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] + 1) % MOD;
      } else {
        dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1]) % MOD;
      }
    }
  }
  cout << dp[N][M] + 1 << endl;
}
