#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
const long long int MAX = -1000000000000000000;
const long long int MIN = 1000000000000000000;
const long long int inf = 1000000000;
const long long int KOK = 100000;
const long long int LOG = 30;
const long long int li = 4005;
const long long int mod = 1000000007;
long long int n, m, b[li], a[li], k, flag, dp[li];
long long int cev;
string s;
vector<int> v;
inline long long int add(long long int x, long long int y) {
  if (x + y >= mod) return x + y - mod;
  return x + y;
}
int main(void) {
  scanf("%lld %lld", &n, &m);
  for (long long int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
  }
  for (long long int i = 0; i < m; i++) {
    scanf("%lld", &b[i]);
  }
  for (long long int i = 0; i <= n + m + 1; i++) {
    dp[i] = 1;
  }
  for (long long int i = n; i >= 1; i--) {
    for (long long int j = i; j < m + i; j++) {
      if ((i & 7) || (j & 7)) {
        if (a[n - i] == b[j - i]) {
          dp[j] = (add(dp[j - 1], dp[j + 1])) % mod;
        } else {
          dp[j] = (add(dp[j - 1], dp[j + 1]) - dp[j]) % mod;
        }
      } else {
        if (a[n - i] == b[j - i]) {
          dp[j] = ((dp[j - 1] + dp[j + 1]));
        } else {
          dp[j] = (dp[j - 1] + dp[j + 1] - dp[j]);
        }
      }
    }
  }
  printf("%lld\n", dp[m] % mod);
  return 0;
}
