#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[n + 1], t[m + 1];
  for (int i = 1; i < n + 1; i++) {
    cin >> s[i];
  }
  for (int i = 1; i < m + 1; i++) {
    cin >> t[i];
  }
  long long dp[n + 1][m + 1], sum[n + 1][m + 1];
  for (int i = 0; i < n + 1; i++) {
    for (int j = 0; j < m + 1; j++) {
      dp[i][j] = 0;
      sum[i][j] = 0;
    }
  }
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < m + 1; j++) {
      if (s[i] != t[j]) {
        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] + dp[i][j] - sum[i - 1][j - 1]) %
          1000000007;
    }
  }
  cout << sum[n][m] + 1 << endl;
  return 0;
}
