#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
long long int dp[3000][3000];
long long int rui[3000][3000];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long int n, m;
  cin >> n >> m;
  vector<long long int> s(n), t(m);
  for (long long int i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (long long int i = 0; i < m; i++) {
    cin >> t[i];
  }
  for (int i = 0; i < 2010; i++) {
    rui[i][0] = 1;
    rui[0][i] = 1;
  }
  long long int ans = 1;
  for (long long int i = 0; i < n; i++) {
    for (long long int j = 0; j < m; j++) {
      if (s[i] == t[j]) {
        dp[i + 1][j + 1] = rui[i][j] % (1000000007);
      }
      rui[i + 1][j + 1] =
          (rui[i][j + 1] + rui[i + 1][j] - rui[i][j] + dp[i + 1][j + 1]) %
          (1000000007);
    }
  }
  for (long long int i = 0; i <= n; i++) {
    for (long long int j = 0; j <= m; j++) {
      ans += dp[i][j] % (1000000007);
    }
  }
  cout << ans % (1000000007) << endl;
}
