#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const long long INF = 1e9 + 228;
const long long INFLL = 1e18;
const long long MOD = 1e9 + 7;
const long double eps = 1e-6;
const long double eps2 = 1e-9;
const long long MOD2 = 998244353;
const long long dosz = 5e5;
const long long SZ = (1 << 18);
const long double PI = atan2l(0, -1);
void fast_io() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}
const long long maxn = 2e3 + 111;
long long dp[maxn][maxn];
void solve() {
  long long n, m;
  cin >> n >> m;
  vector<long long> nums1(n + 1);
  for (long long i = 1; i <= n; i++) cin >> nums1[i];
  vector<long long> nums2(m + 1);
  for (long long i = 1; i <= m; i++) cin >> nums2[i];
  for (long long i = 0; i <= n; i++)
    for (long long j = 0; j <= m; j++) dp[i][j] = 1;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= m; j++) {
      dp[i][j] = 0;
      if (nums1[i] == nums2[j]) {
        dp[i][j] += dp[i][j - 1];
        dp[i][j] += dp[i - 1][j];
      } else {
        dp[i][j] += dp[i][j - 1];
        dp[i][j] += dp[i - 1][j];
        dp[i][j] -= dp[i - 1][j - 1];
      }
      dp[i][j] %= MOD;
    }
  }
  cout << dp[n][m] << endl;
}
signed main() {
  fast_io();
  srand(time(NULL));
  cout << fixed << setprecision(12);
  long long q = 1;
  while (q--) solve();
}
