#include <bits/stdc++.h>
using namespace std;
constexpr long long int INF = std::numeric_limits<long long int>::max();
long long int dp[2001][2001];
vector<long long int> a, b;
long long int sum(long long int i, long long int j) {
  long long int n = 0;
  for (long long int k = 0; k < i; k++) {
    for (long long int l = 0; l < j; l++) {
      n = (n + dp[k][l]) % 1000000007;
    }
  }
  return n;
}
void solve() {
  long long int n, m;
  cin >> n >> m;
  a.resize(n);
  b.resize(m);
  long long int ans = 0;
  for (auto &i : a) {
    cin >> i;
  }
  for (auto &i : b) {
    cin >> i;
  }
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      if (a[i] == b[j]) {
        dp[i][j] = (sum(i, j) + 1) % 1000000007;
      } else {
        dp[i][j] = 0;
      }
    }
  }
  cout << (sum(n, m) + 1) % 1000000007 << endl;
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
