#include <bits/stdc++.h>
using namespace std;
string to_string(string s) { return s; }
template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < (int)v.size() - 1; i++) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}
void debug() { cerr << endl; }
template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}
void print() { cout << endl; }
template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}
int main() {
  int(N), (M);
  scanf("%d %d", &(N), &(M));
  vector<int>(S)(N);
  for (int i = 0; i < (int)(N); i++) scanf("%d", &(S)[i]);
  vector<int>(T)(M);
  for (int i = 0; i < (int)(M); i++) scanf("%d", &(T)[i]);
  vector<vector<long long>> dp(N + 1, vector<long long>(M + 1));
  for (int i = 0; i < (int)N; i++) {
    for (int j = 0; j < (int)M; j++) {
      if (S[i] == T[j]) {
        dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j + 1] + 1) % 1000000007;
      } else {
        dp[i + 1][j + 1] =
            (dp[i][j + 1] + dp[i + 1][j] - dp[i][j]) % 1000000007;
      }
    }
  }
  print((dp[N][M] + 1) % 1000000007);
  return 0;
}
