#include using namespace std; using ll = long long; template istream& operator >> (istream& is, vector& vec) { for(T& x : vec) is >> x; return is; } int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, q; cin >> n >> q; map mp; for(int i = 0; i < n; i++){ int v; cin >> v; mp[v] = i; } int p = 0; ll ans = 0; for(int i = 0; i < q; i++){ int v, nx; cin >> v; nx = mp[v]; ans += abs(nx - p); p = nx; } cout << ans << '\n'; }