#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
const long long linf = 1LL << 62;
const int mod = 1e9 + 7;
const int MAX = 510000;
const int V = 100005;
long long dy[8] = {1, 0, -1, 0, 1, -1, 1, -1};
long long dx[8] = {0, 1, 0, -1, 1, -1, -1, 1};
const double pi = acos(-1);
template <typename T1, typename T2>
inline void chmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &a, T2 b) {
  if (a < b) a = b;
}
template <typename T1, typename T2>
inline void print2(T1 a, T2 b) {
  cout << a << " " << b << endl;
}
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> s(n), t(m);
  for (long long i = 0; i < (n); i++) cin >> s[i];
  for (long long j = 0; j < (m); j++) cin >> t[j];
  vector<vector<long long> > dp(n + 1, vector<long long>(m + 1, 0));
  for (long long i = 0; i < (n + 1); i++) dp[i][0] = 1;
  for (long long j = 0; j < (m + 1); j++) dp[0][j] = 1;
  for (long long i = 0; i < (n); i++) {
    for (long long j = 0; j < (m); j++) {
      if (s[i] == t[j])
        dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j];
      else
        dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j] - dp[i][j];
      if (dp[i + 1][j + 1] < 0) dp[i + 1][j + 1] %= mod;
      dp[i + 1][j + 1] %= mod;
    }
  }
  cout << dp[n][m] << endl;
}
