#include <bits/stdc++.h>
using namespace std;
template <typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) {
  return os << '(' << pai.first << ' ' << pai.second << ')';
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
  cout << '[';
  for (int i = 0, _i = (((int)(v).size())); i < _i; i++) cout << v[i] << ",";
  cout << "]";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> v) {
  cout << "{";
  for (auto p : v) cout << p << ",";
  cout << "}";
  return os;
}
template <typename T, typename V>
ostream &operator<<(ostream &os, const map<T, V> v) {
  cout << "{";
  for (auto p : v) cout << p << ",";
  cout << "}";
  return os;
}
template <typename T>
void get_max(T &a, T b) {
  a = max(a, b);
}
template <typename T>
void get_min(T &a, T b) {
  a = min(a, b);
}
int N, M;
int A[2001], B[2001];
long long dp[2001][2001];
int main(void) {
  iostream::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);
  cin >> N >> M;
  for (int i = (1), _i = (N + 1); i < _i; i++) cin >> A[i];
  for (int i = (1), _i = (M + 1); i < _i; i++) cin >> B[i];
  for (int i = 0, _i = (N + 1); i < _i; i++) dp[i][0] = 1;
  for (int i = 0, _i = (M + 1); i < _i; i++) dp[0][i] = 1;
  for (int i = (1), _i = (N + 1); i < _i; i++)
    for (int j = (1), _j = (M + 1); j < _j; j++) {
      dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
      if (A[i] == B[j]) dp[i][j] += dp[i - 1][j - 1];
      dp[i][j] %= 1000000007;
    }
  cout << dp[N][M] << '\n';
}
