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