#include <bits/stdc++.h>
using namespace std;
const long long inf = 1000000001;
const long long INF = 1e18;
const long long MOD = 1000000007;
char albt[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
                 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
int main() {
  long long n, m;
  cin >> n >> m;
  long long s[n];
  for (int i = 0; i < n; i++) cin >> s[i];
  long long t[m];
  for (int i = 0; i < m; i++) cin >> t[i];
  long long dp[n + 1][m + 1];
  long long sum[n + 1][m + 1];
  for (int i = 0; i <= n; i++) {
    dp[i][0] = 0;
    sum[i][0] = 0;
  }
  for (int i = 0; i <= m; i++) {
    dp[0][i] = 0;
    sum[0][i] = 0;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (s[i - 1] != t[j - 1])
        dp[i][j] = 0;
      else
        dp[i][j] = sum[i - 1][j - 1] + 1;
      sum[i][j] =
          (sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + dp[i][j]) % MOD;
    }
  }
  cout << (sum[n][m] + 1) % MOD << endl;
}
