#include <bits/stdc++.h>
using namespace std;
constexpr long long INF = 1LL * 1000 * 1000 * 1000 * 1000 * 1000 * 1000;
constexpr int OPEN = 1;
constexpr int CLOSE = 0;
struct Event {
  int time;
  int type;
  int id;
};
bool operator<(const Event& left, const Event& right) {
  return make_pair(left.time, left.type) < make_pair(right.time, right.type);
}
struct Envelope {
  int d;
  int id;
  int w;
  int t;
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  vector<Envelope> envelopes(k);
  vector<Event> events;
  for (int i = 0; i < k; ++i) {
    int s, t, d, w;
    cin >> s >> t >> d >> w;
    events.push_back({s, OPEN, i});
    events.push_back({t + 1, CLOSE, i});
    envelopes[i] = {d, i, w, t};
  }
  sort(events.begin(), events.end());
  int p = 0;
  set<array<int, 3>> currEnvelopes;
  vector<int> next(1 + n, -1);
  for (int i = 0; i <= n; ++i) {
    while (p < events.size() && events[p].time == i) {
      if (events[p].type == CLOSE) {
        currEnvelopes.erase({-envelopes[events[p].id].w,
                             -envelopes[events[p].id].d, events[p].id});
      } else if (events[p].type == OPEN) {
        currEnvelopes.insert({-envelopes[events[p].id].w,
                              -envelopes[events[p].id].d, events[p].id});
      }
      ++p;
    }
    if (next[i] == -1 && !currEnvelopes.empty()) {
      next[i] = (*currEnvelopes.begin())[2];
    }
  }
  vector<vector<long long>> dp(1 + m, vector<long long>(1 + n + 1, INF));
  for (int j = 0; j <= m; ++j) {
    dp[j][n + 1] = 0;
  }
  for (int i = n; i >= 0; --i) {
    for (int j = 0; j <= m; ++j) {
      if (next[i] == -1) {
        dp[j][i] = dp[j][i + 1];
      } else {
        dp[j][i] = dp[j][envelopes[next[i]].d + 1] + envelopes[next[i]].w;
        if (j > 0) {
          dp[j][i] = min(dp[j][i], dp[j - 1][i + 1]);
        }
      }
    }
  }
  long long res = INF;
  for (int j = 0; j <= m; ++j) {
    res = min(res, dp[j][0]);
  }
  cout << res << endl;
  return 0;
}
