#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a[n], b[m];
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < m; i++) cin >> b[i];
  long long t[n + 1][m + 1];
  t[0][0] = 1;
  for (int i = 1; i < n + 1; i++) {
    t[i][0] = t[i - 1][0] + (b[0] == a[i - 1]);
  }
  for (int i = 1; i < m + 1; i++) {
    t[0][i] = t[0][i - 1] + (b[i - 1] == a[0]);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      t[i][j] = t[i - 1][j] + t[i][j - 1] - t[i - 1][j - 1];
      if (a[i] == b[j]) t[i][j] += t[i - 1][j - 1];
      t[i][j] %= 1000000007;
    }
  }
  cout << t[n + 1][m + 1];
}
