#include <bits/stdc++.h>
const int N = 1e5 + 5, MAX = 3e7, MOD = 998244353;
using namespace std;
int t, m, n;
pair<pair<int, int>, pair<int, int> > a[N];
int Next[N];
pair<int, int> seg[4 * N], lazy[4 * N], mn[4 * N];
void push(int indx) {
  lazy[indx * 2] = max(lazy[indx], lazy[indx * 2]);
  seg[indx * 2] = max(lazy[indx], seg[indx * 2]);
  lazy[indx * 2 + 1] = max(lazy[indx], lazy[indx * 2 + 1]);
  seg[indx * 2 + 1] = max(lazy[indx], seg[indx * 2 + 1]);
}
pair<int, int> get(int indx, int l, int r, int i, int j) {
  if (l > j || r < i) return {0, 0};
  if (l >= i && r <= j) return seg[indx];
  push(indx);
  pair<int, int> a = get(indx * 2, l, (l + r) / 2, i, j),
                 b = get(indx * 2 + 1, (l + r) / 2 + 1, r, i, j);
  return max(a, b);
}
void update(int indx, int l, int r, int i, int j, int val) {
  if (l > j || r < i || mn[indx].first > a[val].second.second ||
      (a[val].second.second < lazy[indx].first) ||
      (a[val].second.second == lazy[indx].first &&
       a[val].second.first <= a[lazy[indx].second].second.first))
    return;
  if ((l >= i && r <= j) &&
      (a[val].second.second > seg[indx].first ||
       ((a[val].second.second == seg[indx].first) &&
        (a[val].second.first > a[seg[indx].second].second.first)))) {
    lazy[indx] = seg[indx] = {a[val].second.second, val};
    mn[indx] = {a[val].second.second, val};
    return;
  }
  if (l == r) return;
  push(indx);
  update(indx * 2, l, (l + r) / 2, i, j, val);
  update(indx * 2 + 1, (l + r) / 2 + 1, r, i, j, val);
  seg[indx] = max(seg[indx * 2], seg[indx * 2 + 1]);
  mn[indx] = min(mn[indx * 2], mn[indx * 2 + 1]);
}
long long memo[N][205];
long long solve(int indx, int rem) {
  if (indx > t) return 0;
  long long &ret = memo[indx][rem];
  if (ret != -1) return ret;
  ret = 1e18;
  if (rem) {
    ret = min(ret, solve(indx + 1, rem - 1));
  }
  if (Next[indx] < n)
    ret = min(ret, a[Next[indx]].second.second +
                       solve(a[Next[indx]].second.first + 1, rem));
  else
    ret = min(ret, solve(indx + 1, rem));
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  scanf("%d %d %d", &t, &m, &n);
  for (int i = 0; i < n; i++) {
    scanf("%d %d %d %d", &a[i].first.first, &a[i].first.second,
          &a[i].second.first, &a[i].second.second);
    int l = a[i].first.first, r = a[i].first.second;
    update(1, 1, t, l, r, i);
  }
  for (int i = 1; i <= t; i++) {
    pair<int, int> p = get(1, 1, t, i, i);
    if (p.first != 0)
      Next[i] = p.second;
    else
      Next[i] = n;
  }
  memset(memo, -1, sizeof(memo));
  printf("%lld\n", solve(1, m));
}
