#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> v1;
  vector<int> v2;
  int n, m;
  long long int ans = 0;
  cin >> n >> m;
  int tmp;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    v1.push_back(tmp);
  }
  for (int i = 0; i < m; i++) {
    cin >> tmp;
    v2.push_back(tmp);
  }
  long long int **dp = new long long int *[n];
  for (int i = 0; i < n; i++) {
    dp[i] = new long long int[m];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      dp[i][j] = 0;
      if (v1[i] == v2[j]) {
        for (int k = 0; k < i; k++) {
          for (int t = 0; t < j; t++) {
            dp[i][j] += dp[k][t];
          }
          dp[i][j] %= 1000000007;
        }
        dp[i][j]++;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      ans += dp[i][j];
      ans %= 1000000007;
    }
  }
  ans++;
  cout << ans;
}
