#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
long long a[2003], b[2003], dp[2003][2003];
int32_t main() {
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);
  ;
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < m; i++) cin >> b[i];
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (a[i] == b[j]) {
        dp[i][j]++;
        if (i) dp[i][j] += dp[i - 1][j];
        if (j) dp[i][j] += dp[i][j - 1];
        dp[i][j] %= M;
      } else {
        if (i) dp[i][j] += dp[i - 1][j];
        if (j) dp[i][j] += dp[i][j - 1];
        if (i && j) dp[i][j] -= dp[i - 1][j - 1];
        dp[i][j] %= M;
      }
    }
  }
  cout << (dp[n - 1][m - 1] + 1) % M << endl;
}
