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