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