#include <bits/stdc++.h>
using namespace std;
long long arr[90][90], dp[83][83][83][2], n, k;
long long bt(long long a, long long b, long long c, bool dir) {
  if (!c) return 0;
  if (b < a) return 1e9;
  if (dp[a][b][c][dir] != -1) return dp[a][b][c][dir];
  long long ret = 1e9;
  if (dir) {
    for (long long f = a; f <= b; f++) {
      ret = min(ret, arr[b + 1][f] + bt(a, f - 1, c - 1, 1));
      ret = min(ret, arr[b + 1][f] + bt(f + 1, b, c - 1, 0));
    }
  } else {
    for (long long f = a; f <= b; f++) {
      ret = min(ret, arr[a - 1][f] + bt(a, f - 1, c - 1, 1));
      ret = min(ret, arr[a - 1][f] + bt(f + 1, b, c - 1, 0));
    }
  }
  return dp[a][b][c][dir] = ret;
}
int main() {
  memset(dp, -1, sizeof dp);
  cin >> n >> k;
  for (long long f = 1; f <= n; f++)
    for (long long f1 = 1; f1 <= n; f1++) arr[f][f1] = 1e9;
  long long m;
  cin >> m;
  for (long long f = 0; f < m; f++) {
    long long a, b, c;
    cin >> a >> b >> c;
    arr[a][b] = min(arr[a][b], c);
  }
  long long ans = bt(1, n, k, 0);
  if (ans > 1e8) ans = -1;
  cout << ans << endl;
}
