#include <bits/stdc++.h>
using namespace std;
const long long N = 2e3 + 10, mod = 1e9 + 7;
long long n, m, ans = 1, s[N], t[N], psum[N][N];
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) cin >> s[i];
  for (long long i = 1; i <= m; i++) cin >> t[i];
  for (long long i = 1; i <= n; i++)
    for (long long j = 1; j <= m; j++) {
      ans = (ans + (s[i] == t[j]) * (psum[i - 1][j - 1] + 1)) % mod;
      psum[i][j] = (psum[i][j - 1] + psum[i - 1][j] - psum[i - 1][j - 1] +
                    (s[i] == t[j]) * (psum[i - 1][j - 1] + 1)) %
                   mod;
    }
  cout << ans << endl;
}
