#include <bits/stdc++.h>
using namespace std;
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 62;
constexpr auto mod = 1000000007;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
long long dp[2010][2010];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> s(n), t(m);
  dp[0][0] = 1;
  for (int(i) = (0); (i) < (n); (i)++) cin >> s[i];
  for (int(i) = (0); (i) < (m); (i)++) cin >> t[i];
  dp[0][0] = 1;
  for (int(i) = (0); (i) <= (n); (i)++)
    for (int(j) = (0); (j) <= (m); (j)++) {
      if (i - 1 >= 0 && j - 1 >= 0 && s[i - 1] == t[j - 1])
        dp[i][j] += dp[i - 1][j - 1];
      if (i - 1 >= 0) dp[i][j] += dp[i - 1][j];
      if (j - 1 >= 0) dp[i][j] += dp[i][j - 1];
      if (i - 1 >= 0 && j - 1 >= 0) dp[i][j] -= dp[i - 1][j - 1];
      dp[i][j] %= mod;
    }
  cout << dp[n][m] << endl;
}
