#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  for (int i = (0); i < (v.size()); i++) os << v[i] << " ";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
  for (typename set<T>::iterator it = v.begin(); it != v.end(); it++)
    os << *it << " ";
  return os;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& v) {
  os << v.first << " " << v.second << endl;
  return os;
}
const int mod = 1e9 + 7;
const int maxn = 1e5 + 5;
const int maxh = 1e3 + 5;
int N, M;
vector<int> A;
vector<int> B;
int dp[maxh][maxh];
int add(long long a, long long b) { return (int)((a + b) % mod); }
int sub(long long a, long long b) { return (int)((a - b + mod) % mod); }
int main() {
  cin >> N >> M;
  for (int i = (0); i < (N); i++) {
    int num;
    scanf("%d", &num);
    A.push_back(num);
  }
  for (int i = (0); i < (M); i++) {
    int num;
    scanf("%d", &num);
    B.push_back(num);
  }
  for (int i = (0); i <= (N); i++) {
    dp[0][i] = 1;
  }
  for (int i = (0); i <= (M); i++) {
    dp[i][0] = 1;
  }
  for (int i = (1); i <= (M); i++) {
    for (int j = (1); j <= (N); j++) {
      if (B[i - 1] == A[j - 1]) {
        dp[i][j] = add(dp[i - 1][j], dp[i][j - 1]);
      } else {
        dp[i][j] = add(dp[i - 1][j], dp[i][j - 1]);
        dp[i][j] = sub(dp[i][j], dp[i - 1][j - 1]);
      }
    }
  }
  cout << dp[M][N] << endl;
  return 0;
}
