#include <bits/stdc++.h>
using namespace std;
long long CommomSubsequencesCount(int s[], int t[], int n, int m) {
  int n1 = n;
  int n2 = m;
  long long dp[n1 + 1][n2 + 1];
  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]) % 1000000007;
      else
        dp[i][j] =
            (dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1]) % 1000000007;
    }
  }
  return dp[n1][n2];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int 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];
  }
  long long ans = CommomSubsequencesCount(s, t, n, m);
  cout << ans + 1 << '\n';
}
