#include <bits/stdc++.h>
using namespace std;
using Edge = pair<int, int>;
using Graph = vector<vector<int>>;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
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;
}
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
int main() {
  long long N, M, ans = 0;
  cin >> N >> M;
  long long S[N + 1], T[M + 1], DP[N + 1][M + 1], SUM[N + 1][M + 1];
  for (int i = (1); i <= (N); ++i) cin >> S[i];
  for (int i = (1); i <= (M); ++i) cin >> T[i];
  for (int i = (0); i < (N + 1); ++i) {
    for (int j = (0); j < (M + 1); ++j) {
      DP[i][j] = 0;
      SUM[i][j] = 0;
    }
  }
  for (int i = (1); i <= (N); ++i) {
    for (int j = (1); j <= (M); ++j) {
      if (S[i] == T[j]) {
        DP[i][j] = SUM[i - 1][j - 1] + 1;
      } else {
        DP[i][j] = 0;
      }
      DP[i][j] %= 1000000007;
      SUM[i][j] = SUM[i - 1][j] + SUM[i][j - 1] - SUM[i - 1][j - 1] + DP[i][j];
      SUM[i][j] %= 1000000007;
    }
  }
  SUM[N][M] = (SUM[N][M] + 1) % 1000000007;
  cout << SUM[N][M] << '\n';
  return 0;
}
