#include <bits/stdc++.h>
using namespace std;
template <typename T = long long>
inline T IN() {
  T x;
  cin >> x;
  return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&...tail) {
  cin >> head;
  CIN(move(tail)...);
}
template <typename T = string>
inline void eputs(T s) {
  cout << s << "\n";
  exit(0);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}
template <typename T>
using PQG = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
using PQ = priority_queue<T>;
const long long INF = 1e9;
const long long MOD = 1e9 + 7;
const long long LINF = 1e18 + 1;
const long long dx[] = {1, -1, 0, 0};
const long long dy[] = {0, 0, 1, -1};
long long N, M;
vector<long long> S, T;
long long dp[long long(2 * 1e3 + 1)][long long(2 * 1e3 + 1)];
signed main() {
  cin >> N >> M;
  for (long long i = 0; i < (N); ++i) {
    S.emplace_back(IN());
  }
  for (long long i = 0; i < (M); ++i) {
    T.emplace_back(IN());
  }
  long long ans = 0;
  for (long long i = 0; i < (N); ++i) {
    long long sum = 0, tmp = 0;
    for (long long j = 0; j < (M); ++j) {
      dp[i + 1][j] = dp[i][j];
      if (S[i] == T[j]) {
        dp[i + 1][j] += sum + 1;
        dp[i + 1][j] %= MOD;
      }
      (sum += dp[i][j]) %= MOD;
      tmp = max(tmp, dp[i + 1][j]);
    }
    (ans += tmp) %= MOD;
  }
  cout << ans + 1 << "\n";
}
