#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a[1000], b[1000];
  int dp[6002][6002];
  memset(dp, 0, sizeof dp);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (a[i - 1] == b[j - 1]) {
        dp[i][j] = (1 + dp[i - 1][j] % 100000007 + dp[i][j - 1] % 100000007) %
                   100000007;
      } else {
        dp[i][j] = (dp[i - 1][j] % 100000007 + dp[i][j - 1] % 100000007 -
                    dp[i - 1][j - 1] % 100000007 + 100000007) %
                   100000007;
      }
    }
  }
  cout << (dp[n][m] + 1) % 100000007;
  return 0;
}
