#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
const int INF = (int)1e9;
const long long IINF = LLONG_MAX;
const int maxn = 10000005;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(m);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < m; i++) cin >> b[i];
  int dp[n + 1][m + 1];
  memset(dp, 0, sizeof(dp));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      dp[i][j] = (1LL * dp[i][j - 1] + dp[i - 1][j]) % 1000000007;
      dp[i][j] = (dp[i][j] - dp[i - 1][j - 1]) % 1000000007;
      if (a[i - 1] == b[j - 1]) {
        dp[i][j] = (1LL * dp[i - 1][j - 1] + 1 + dp[i][j]) % 1000000007;
      }
    }
  }
  cout << (dp[n][m] + 1) % 1000000007;
}
