#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
using ld = long double;
int ctoi(const char c) {
  if ('0' <= c && c <= '9') return (c - '0');
  return -1;
}
ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
constexpr ll MOD = 1000000007;
constexpr ll INF = 1000000011;
constexpr ll MOD2 = 998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS = 10e-8;
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
  for (auto&& x : v) is >> x;
  return is;
}
template <typename T, typename U>
istream& operator>>(istream& is, pair<T, U>& p) {
  is >> p.first;
  is >> p.second;
  return is;
}
template <typename T, typename U>
ostream& operator>>(ostream& os, const pair<T, U>& p) {
  os << p.first << ' ' << p.second;
  return os;
}
template <class T>
ostream& operator<<(ostream& os, vector<T>& v) {
  for (auto i = begin(v); i != end(v); ++i) {
    if (i != begin(v)) os << ' ';
    os << *i;
  }
  return os;
}
ll dp[2007][2007];
int main() {
  ll N, M, A[2007], B[2007];
  cin >> N >> M;
  for (ll i = 0; i < (N); ++i) {
    cin >> A[i];
    dp[i + 1][0] = 1;
  }
  for (ll i = 0; i < (M); ++i) {
    cin >> B[i];
    dp[0][i + 1] = 1;
  }
  dp[0][0] = 1;
  for (ll i = (1); i < (N + 1); ++i) {
    for (ll j = (1); j < (M + 1); ++j) {
      if (A[i - 1] == B[j - 1]) {
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
        dp[i][j] %= MOD;
      } else {
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
        dp[i][j] %= MOD;
      }
    }
  }
  cout << dp[N][M] % MOD << '\n';
}
