#include <bits/stdc++.h>
using namespace std;
long long n, m, s[2003], t[2003], d[2003][2003];
bool db = 0;
long long a(long long u, long long v) {
  long long res = (u + v) % 1000000007;
  if (res < 0) res += 1000000007;
  return res;
}
long long dp(long long u, long long v) {
  long long &ans = d[u][v];
  if (ans != LONG_MIN) {
    return ans;
  }
  if (u == 0 || v == 0) return ans = 1;
  return ans = a(a(dp(u, v - 1), dp(u - 1, v)),
                 (s[u] != t[v]) * dp(u - 1, v - 1));
}
signed main() {
  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 = 0; i <= n; i++)
    for (long long j = 0; j <= m; j++) d[i][j] = LONG_MIN;
  cout << dp(n, m);
}
