#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
 
using namespace std;
 
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define rep(i,n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
#define DBG(X) cout<<" "<<#X<<" : "<<X<<endl
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;

const int INF = 1e9;
const double EPS = 1e-8;
const int mod = 1e9 + 7;
const ll LINF = 1e18;

struct Input
{
	int n;char c;char str[1024];string s;ll l;
	int nextInt(){scanf("%d", &n);return n;}
	ll nextLong(){scanf("%lld", &l);return l;}
	char nextChar(){scanf("%c", &c);return c;}
	string next(){scanf("%s", str);return string(str);}
	string nextLine(){getline(cin, s);return s;}
};
Input in;


int main(){
	int d = in.nextInt();
	vi v;
	int x = in.nextInt();
	rep(i, x){
		char c;
		int p;
		cin>>c>>p;
		if(c == 'D') v.pb(p);
	}
	vi u;
	int y = in.nextInt();
	rep(i, y){
		string s = in.next();
		int p = in.nextInt();
		if(s == "DD") u.pb(p);
	}
	sort(rall(v));
	sort(rall(u));
	int ans = 0;
	for(int i = 0; i <= u.size() && i * 2 <= d; i++){
		int j = d - i * 2, tmp = 0;
		j = min(j, (int)v.size());
		rep(k, j) tmp += v[k];
		rep(k, i) tmp += u[k];
		ans = max(tmp, ans);
	}
	cout<<ans<<endl;
}