#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> dp(n+1, 0);

    int x;
    cin >> x;
    while(--x >= 0){
        string s;
        int p;
        cin >> s >> p;
        if(s == "D"){
            for(int i=1; i<=n; ++i)
                dp[i-1] = max(dp[i-1], dp[i] + p);
        }
    }

    int y;
    cin >> y;
    while(--y >= 0){
        string s;
        int p;
        cin >> s >> p;
        if(s == "DD"){
            for(int i=2; i<=n; ++i)
                dp[i-2] = max(dp[i-2], dp[i] + p);
        }
    }

    cout << dp[0] << endl;
    return 0;
}