#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
signed main() {
  long long n, m;
  cin >> n >> m;
  long long s[n + 1], t[m + 1];
  for (long long i = 1; i < n + 1; i++) {
    cin >> s[i];
  }
  for (long long i = 1; i < m + 1; i++) {
    cin >> t[i];
  }
  long long sum[n + 1][m + 1];
  long long dp_sum = 0;
  for (long long i = 0; i < n + 1; i++) {
    for (long long j = 0; j < m + 1; j++) {
      if (i == 0 || j == 0) {
        sum[i][j] = 0;
        continue;
      }
      long long dp;
      if (s[i] != t[j]) {
        dp = 0;
      } else {
        dp = sum[i - 1][j - 1] + 1;
      }
      sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + dp;
      sum[i][j] %= MOD;
    }
  }
  cout << (sum[n][m] + 1) % MOD << endl;
  return 0;
}
