#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
const long long MOD = 1000000007;
const int N = 2005;
int s[N], t[N];
long long dp[N][N];
long long pow2[N];
int main() {
  pow2[0] = 1;
  for (int i = 0; i < (int)N - 1; ++i) pow2[i + 1] = (pow2[i] << 1) % MOD;
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < (int)n; ++i) scanf("%d", &s[i]);
  for (int i = 0; i < (int)m; ++i) scanf("%d", &t[i]);
  long long ret = 1;
  dp[0][0] = 0;
  for (int i = 1; i < (int)n + 1; ++i) {
    for (int j = 1; j < (int)m + 1; ++j) {
      if (s[i - 1] == t[j - 1])
        dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] + 1) % MOD;
      else
        dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1]) % MOD;
    }
  }
  cout << dp[n][m] + 1 << endl;
  return 0;
}
