#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
struct mint {
  int n;
  mint(int n_ = 0) : n(n_) {}
};
mint operator-(mint a) { return -a.n + MOD * (a.n != 0); }
mint operator+(mint a, mint b) {
  int x = a.n + b.n;
  return x - (x >= MOD) * MOD;
}
mint operator-(mint a, mint b) {
  int x = a.n - b.n;
  return x + (x < 0) * MOD;
}
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }
istream &operator>>(istream &i, mint &a) { return i >> a.n; }
ostream &operator<<(ostream &o, mint a) { return o << a.n; }
vector<mint> F_{1, 1}, R_{1, 1}, I_{0, 1};
void check_fact(int n) {
  for (int i = I_.size(); i <= n; i++) {
    I_.push_back(I_[MOD % i] * (MOD - MOD / i));
    F_.push_back(F_[i - 1] * i);
    R_.push_back(R_[i - 1] * I_[i]);
  }
}
mint I(int n) {
  check_fact(abs(n));
  return n >= 0 ? I_[n] : -I_[n];
}
mint F(int n) {
  check_fact(n);
  return n < 0 ? 0 : F_[n];
}
mint R(int n) {
  check_fact(n);
  return n < 0 ? 0 : R_[n];
}
mint C(int n, int r) { return F(n) * R(n - r) * R(r); }
mint P(int n, int r) { return F(n) * R(n - r); }
mint H(int n, int r) { return n == 0 ? (r == 0) : C(n + r - 1, r); }
int N, M;
int S[2001], T[2001];
int dp[2001][2001];
int main(void) {
  cin >> N >> M;
  for (int i = 0; i < (N); i++) cin >> S[i + 1];
  for (int i = 0; i < (M); i++) cin >> T[i + 1];
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= M; j++) {
      if (S[i] == T[j])
        dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] + 1) % MOD;
      else
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
    }
  }
  cout << dp[N][M] + 1 << endl;
  return 0;
}
