#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007LL;
const long long INF = 1LL << 60;
using vll = vector<long long>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
long long dx[4] = {0, 1, 0, -1};
long long dy[4] = {1, 0, -1, 0};
int main() {
  long long n, m;
  cin >> n >> m;
  vll s(n), t(m);
  for (long long i = 0; i < (n); i++) cin >> s[i];
  for (long long i = 0; i < (m); i++) cin >> t[i];
  vvll dp(n + 1, vll(m + 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 + 1][j] + dp[i][j + 1] - dp[i][j]) + dp[i][j] + 1;
        dp[i + 1][j + 1] %= MOD;
      } else {
        dp[i + 1][j + 1] = dp[i + 1][j] + dp[i][j + 1] - dp[i][j];
      }
    }
  cout << (dp[n][m] + 1) << "\n";
}
