#include <bits/stdc++.h>
const long long MAXN = 1000000000000000LL;
struct pa {
  int first;
  int second;
  bool operator<(pa const& b) const {
    return first > b.first || (first == b.first && second > b.second);
  }
};
int main() {
  int n, m, k;
  std::cin >> n >> m >> k;
  std::vector<std::vector<long long>> d(n + 2,
                                        std::vector<long long>(m + 1, MAXN));
  d[1][m] = 0;
  std::map<pa, int> s;
  std::vector<std::pair<int, int>> p(2 * k);
  std::vector<int> a(k), b(k), w(k), dw(k);
  for (int i = 0; i < k; ++i) {
    std::cin >> a[i] >> b[i] >> dw[i] >> w[i];
    p[2 * i] = {a[i], -(i + 1)};
    p[2 * i + 1] = {b[i], i + 1};
  }
  std::sort(p.begin(), p.end(),
            [](std::pair<int, int> const& x, std::pair<int, int> const& y) {
              return x.first < y.first ||
                     (x.first == y.first && x.second < y.second);
            });
  int j = 0;
  for (int i = 1; i <= n; ++i) {
    for (; j < 2 * k && p[j].first <= i && p[j].second < 0; ++j) {
      if (s.count({w[-p[j].second - 1], dw[-p[j].second - 1]}) == 0)
        s[{w[-p[j].second - 1], dw[-p[j].second - 1]}] = 1;
      else
        ++s[{w[-p[j].second - 1], dw[-p[j].second - 1]}];
    }
    pa x = {-1, -1};
    if (!s.empty()) x = (*s.begin()).first;
    for (int z = 0; z <= m; ++z) {
      if (z > 0) d[i + 1][z - 1] = std::min(d[i + 1][z - 1], d[i][z]);
      if (x.first != -1) {
        d[x.second + 1][z] = std::min(d[x.second + 1][z], d[i][z] + x.first);
      } else {
        d[i + 1][z] = std::min(d[i + 1][z], d[i][z]);
      }
    }
    for (; j < 2 * k && p[j].first <= i && p[j].second > 0; ++j)
      if (s[{w[p[j].second - 1], dw[p[j].second - 1]}] > 1)
        --s[{w[p[j].second - 1], dw[p[j].second - 1]}];
      else
        s.erase({w[p[j].second - 1], dw[p[j].second - 1]});
  }
  long long res = MAXN;
  for (int i = 0; i <= m; ++i) res = std::min(res, d[n + 1][i]);
  std::cout << res << "\n";
}
