#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, m, i, j, k, ans, ss;
  cin >> n >> m;
  vector<long long> s(n + 1), t(m + 1);
  for (i = 1; i <= n; i++) cin >> s[i];
  for (i = 1; i <= m; i++) cin >> t[i];
  vector<vector<long long>> dp(n + 1, vector<long long>(m + 1, 0));
  vector<vector<long long>> sum(n + 1, vector<long long>(m + 1, 0));
  ans = 1;
  sum[0].assign(m + 1, 1);
  for (i = 1; i <= n; i++) sum[i][0] = 1;
  for (i = 1; i <= n; i++) {
    ss = 0;
    for (j = 1; j <= m; j++) {
      if (s[i] == t[j]) {
        dp[i][j] = sum[i - 1][j - 1];
        ans += sum[i - 1][j - 1];
      }
      ss += dp[i][j];
      sum[i][j] = sum[i - 1][j] + ss;
    }
  }
  cout << ans % 1000000007LL << "\n";
  return 0;
}
