#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
const long long int inf = 1e18;
int main() {
  long long int n, m;
  cin >> n >> m;
  long long 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];
  long long int dp[n + 1][m + 1];
  memset(dp, 0, sizeof(dp));
  long long int l[n + 1][m + 1];
  memset(l, 0, sizeof(l));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i] == t[j]) dp[i + 1][j + 1] = l[i][j] + 1;
      dp[i + 1][j + 1] %= mod;
      l[i + 1][j + 1] = -l[i][j] + l[i + 1][j] + l[i][j + 1] + dp[i + 1][j + 1];
      l[i + 1][j + 1] %= mod;
    }
  }
  cout << (l[n][m] + 1) % mod << endl;
}
