#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,std::string> P;

const int INF = 1001001001;

// S N E W(南北東西)
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

int D, X, Y;
std::vector<int> A, B;

int main(){
    std::cin >> D;
    
    std::cin >> X;
    REP(i, X){
        char a;
        int p;
        std::cin >> a >> p;

        if(a == 'D'){A.push_back(p);}
    }
    std::sort(A.begin(), A.end(), std::greater<int>());
    
    std::cin >> Y;
    REP(i, Y){
        std::string b;
        int q;
        std::cin >> b >> q;
        
        if(b == "DD"){B.push_back(q);}
    }
    std::sort(B.begin(), B.end(), std::greater<int>());

    int res = 0;
    REP(i, D+1){
        int x = i, y = D - i;
        int value = 0;
        
        for(auto a : A){
            if(x > 0){value += a; x -= 1;}
        }

        for(auto b : B){
            if(y > 1){value += b; y -= 2;}
        }

        res = std::max(res, value);
    }

    std::cout << res << std::endl;
}