#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int ans = 1;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(n), t(m);
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < m; i++) cin >> t[i];
  vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      dp[i + 1][j + 1] = (dp[i][j + 1] + dp[i + 1][j] - dp[i][j]) % MOD;
      if (s[i] == t[j]) {
        dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j] + 1) % MOD;
      }
    }
  }
  cout << (dp[n][m] + 1) % MOD << endl;
}
