#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

signed main(){
    
    int D;
    cin >> D;
    
    int x, y;
    cin >> x;

    vector<int> v, w;
    for(int i = 0; i < x; ++i){
        string s;
        int tmp;
        cin >> s >> tmp;
        if(s == "D"){
            v.push_back(tmp);
        }
    }

    cin >> y;
    for(int i = 0; i < y; ++i){
        string s;
        int tmp;
        cin >> s >> tmp;
        if(s ==  "DD"){
            w.push_back(tmp);
        }
    }

    //cout << "hoge" << endl;
    sort(v.begin(), v.end(), greater<int>());
    sort(w.begin(), w.end(), greater<int>());
    int ans = 0;
    for(int i = 0; i <= D; ++i){
        int sum = 0;
        for(int j = 0; j < i && j < v.size(); ++j){
            sum += v[j];
        }
        int res = (D - i) / 2;
        for(int j = 0; j < res && j < w.size(); ++j){
            sum += w[j];
        }
        ans = max(ans, sum);
    }
    cout << ans << endl;
    return 0;
}

