#include #include using namespace std; using namespace atcoder; #define ll long long #define rep(i,a,b) for(int i=(a);i<(b);i++) #define repl(i,a,b) for(ll i=(a);i<(b);i++) #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() template bool chmin(T &a,T b){if(a>b){a=b;return true;} return false;} template bool chmax(T &a,T b){if(a> n >> m; mapmp; rep(i,0,n){ string s; ll p; cin >> s >> p; mp[s]=p; } ll ans=0; rep(i,0,m){ string t; cin >> t; ans+=mp[t]; } cout << ans << "\n"; return; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int T=1; // cin >> T; rep(_,0,T){ solve(); } }