#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long n, m, s[2009], t[2009], dp[2009][2009];
signed main() {
  cin >> n >> m;
  for (long long i = 0; i++ < n;) cin >> s[i];
  for (long long i = 0; i++ < m;) cin >> t[i];
  for (long long i = 0; i++ < n;)
    for (long long j = 0; j++ < m;) {
      dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
      if (s[i] == t[j]) dp[i][j] += dp[i - 1][j - 1] + 1;
      dp[i][j] %= mod;
    }
  cout << (dp[n][m] + 1) % mod << endl;
}
