#include <bits/stdc++.h>
using namespace std;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
long long modpow(long long n, long long k) {
  if (k == 1) {
    return n;
  } else if (k == 0) {
    return 1;
  } else if (k % 2 == 0) {
    long long memo = modpow(n, k / 2) % 1000000007;
    return memo * memo % 1000000007;
  } else {
    return n * modpow(n, k - 1) % 1000000007;
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  int s[n], t[m];
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> t[i];
  }
  long long ans = 1;
  long long dp[n][m];
  long long sumDP[n][m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      dp[i][j] = 0;
      sumDP[i][j] = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i] == t[j]) {
        if (i == 0 || j == 0) {
          dp[i][j] = 1;
        } else {
          dp[i][j] = sumDP[i - 1][j - 1] + 1;
          dp[i][j] %= 1000000007;
        }
      }
      if (i == 0) {
        if (j == 0) {
          sumDP[i][j] = dp[i][j];
        } else {
          sumDP[i][j] = sumDP[i][j - 1] + dp[i][j];
        }
        sumDP[i][j] %= 1000000007;
      } else if (j == 0) {
        sumDP[i][j] = sumDP[i - 1][j] + dp[i][j];
        sumDP[i][j] %= 1000000007;
      } else {
        sumDP[i][j] =
            sumDP[i - 1][j] + sumDP[i][j - 1] - sumDP[i - 1][j - 1] + dp[i][j];
        sumDP[i][j] %= 1000000007;
      }
    }
  }
  ans += sumDP[n - 1][m - 1];
  ans %= 1000000007;
  cout << ans << endl;
  return 0;
}
