#include <bits/stdc++.h>
using namespace std;
int n, kk, m;
int e[82][82];
int main() {
  cin >> n >> kk;
  cin >> m;
  for (int i = 0; i < 82; i++) {
    for (int j = 0; j < 82; j++) {
      e[i][j] = 0x7fffffff;
    }
  }
  while (m--) {
    int u, v, k;
    cin >> u >> v >> k;
    e[u][v] = min(e[u][v], k);
  }
  for (int i = n; i > 0; i--) e[n + 1][i] = 0;
  int r[82][82][82];
  for (int i = 0; i < 82; i++) {
    for (int j = 0; j < 82; j++) {
      for (int k = 0; k < 82; k++) {
        r[i][j][k] = 0x7fffffff;
      }
    }
  }
  for (int diff = 1; diff <= n + 1; diff++) {
    for (int i = 0; i + diff <= n + 1; i++) {
      int j = i + diff;
      r[i][j][0] = 0;
      for (int k = 1; k < diff; k++) {
        for (int l = i + 1; l < j; l++) {
          if (e[j][l] < 0x7fffffff &&
              min(r[i][l][k - 1], r[j][l][k - 1]) < 0x7fffffff) {
            r[i][j][k] =
                min(r[i][j][k], e[j][l] + min(r[i][l][k - 1], r[j][l][k - 1]));
          }
        }
      }
    }
    for (int i = n + 1; i - diff >= 0; i--) {
      int j = i - diff;
      r[i][j][0] = 0;
      for (int k = 1; k < diff; k++) {
        for (int l = j + 1; l < i; l++) {
          if (e[j][l] < 0x7fffffff &&
              min(r[i][l][k - 1], r[j][l][k - 1]) < 0x7fffffff) {
            r[i][j][k] =
                min(r[i][j][k], e[j][l] + min(r[i][l][k - 1], r[j][l][k - 1]));
          }
        }
      }
    }
  }
  if (r[0][n + 1][kk] == 0x7fffffff)
    cout << -1 << endl;
  else
    cout << r[0][n + 1][kk] << endl;
  return 0;
}
