#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
const int MOD = 1000000007;
const long long INF = 1e18;
const int MX = 3005;
const long double PI = 4 * atan((long double)1);
template <class T>
void ckmin(T &a, T b) {
  a = min(a, b);
}
template <class T>
void ckmax(T &a, T b) {
  a = max(a, b);
}
long long dp[MX][MX];
long long a[MX], b[MX];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < (N); i++) cin >> a[i];
  for (int i = 0; i < (M); i++) cin >> b[i];
  dp[0][0] = 0;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      if (a[i - 1] == b[j - 1]) {
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1] + 1;
      } else {
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
      }
      dp[i][j] %= MOD;
    }
  }
  cout << (dp[N][M] + 1) % MOD << "\n";
}
