/*  -*- coding: utf-8 -*-
 *
 * 2929.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_M = 100000;
const int MAX_E2 = 1 << 18; // = 262144
const int INF = 1 << 30;

/* typedef */

typedef long long ll;
typedef pair<int,int> pii;

template <typename T, const int MAX_E2>
struct SegTreeMin {
  int n, e2;
  T nodes[MAX_E2], dls[MAX_E2], inf;
  SegTreeMin() {}

  void init(int _n, T _inf) {
    n = _n, inf = _inf;
    for (e2 = 1; e2 < n; e2 <<= 1);
    fill(nodes, nodes + MAX_E2, inf);
    fill(dls, dls + MAX_E2, 0);
  }

  T &get(int i) { return nodes[e2 - 1 + i]; }
  void set(int i, T v) { get(i) = v; }

  void setall() {
    for (int j = e2 - 2; j >= 0; j--)
      nodes[j] = min<T>(nodes[j * 2 + 1], nodes[j * 2 + 2]);
  }

  void _update(int k) {
    if (dls[k] != 0) {
      int k0 = k * 2 + 1, k1 = k0 + 1;
      nodes[k0] += dls[k], nodes[k1] += dls[k];
      dls[k0] += dls[k], dls[k1] += dls[k];
      dls[k] = 0;
    }
  }
  
  void add_range(int r0, int r1, T v, int k, int i0, int i1) {
    if (r1 <= i0 || i1 <= r0) return;
    if (r0 <= i0 && i1 <= r1) {
      nodes[k] += v;
      dls[k] += v;
      return;
    }

    _update(k);

    int im = (i0 + i1) / 2;
    int k0 = k * 2 + 1, k1 = k0 + 1;
    add_range(r0, r1, v, k0, i0, im);
    add_range(r0, r1, v, k1, im, i1);
    nodes[k] = min<T>(nodes[k0], nodes[k1]);
  }
  void add_range(int r0, int r1, T v) { add_range(r0, r1, v, 0, 0, e2); }
  
  T min_range(int r0, int r1, int k, int i0, int i1) {
    if (r1 <= i0 || i1 <= r0) return INF;
    if (r0 <= i0 && i1 <= r1) return nodes[k];

    _update(k);

    int im = (i0 + i1) / 2;
    T v0 = min_range(r0, r1, k * 2 + 1, i0, im);
    T v1 = min_range(r0, r1, k * 2 + 2, im, i1);
    return min<T>(v0, v1);
  }
  T min_range(int r0, int r1) { return min_range(r0, r1, 0, 0, e2); }
};

/* global variables */

pii bas[MAX_N], cds[MAX_M + 1];
SegTreeMin<int,MAX_E2> st;

/* subroutines */

bool ltbas(const pii &a, const pii &b) {
  return a.first > b.first || (a.first == b.first && a.second < b.second);
}

void printpiis(int n, pii ps[]) {
  for (int i = 0; i < n; i++) printf("(%d,%d)", ps[i].first, ps[i].second);
  putchar('\n');
}

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  for (int i = 0; i < n; i++)
    scanf("%d%d", &bas[i].second, &bas[i].first);
  sort(bas, bas + n, ltbas);
  //printpiis(n, bas);

  int k = 0;
  for (int i = 0; i < m; i++) {
    int ci, di;
    scanf("%d%d", &ci, &di);
    if (k == 0 || (cds[k - 1].first < ci && cds[k - 1].second > di))
      cds[k++] = pii(ci, di);
    else if (cds[k - 1].first == ci &&
	     cds[k - 1].second < di && cds[k - 1].second > di)
      cds[k - 1] = pii(ci, di);
  }
  //printpiis(k, cds);

  st.init(k, INF);
  for (int i = 0; i < k; i++) st.set(i, cds[i].second - 1);
  st.setall();

  ll bsum = 0;
  for (int i = 0; i < n; i++) {
    int &bi = bas[i].first, &ai = bas[i].second;
    int l = upper_bound(cds, cds + k, pii(ai, INF)) - cds;
    int dl = st.min_range(0, l);

    if (dl > 0) {
      bsum += bi;
      st.add_range(0, l, -1);
    }

    //printf("(%d,%d): l=%d, dl=%d\n", ai, bi, l, dl);
  }

  printf("%lld\n", bsum);
  return 0;
}



Measured memory_bytes: 6840