#include <bits/stdc++.h>
using namespace std;
int M[80][80][80][80];
int G[80][80];
int go(int fr, int i, int to, int k) {
  int& r = M[fr][i][to][k];
  if (r) return r;
  if (k == 1) return r = 1;
  r = 1000000;
  if (max(i - fr + 1, to - i + 1) < k) return r;
  for (int j = fr; j < i; ++j)
    if (G[i][j] < 1000000) r = min(r, G[i][j] + go(fr, j, i - 1, k - 1));
  for (int j = i + 1; j <= to; ++j)
    if (G[i][j] < 1000000) r = min(r, G[i][j] + go(i + 1, j, to, k - 1));
  return r;
}
int main() {
  for (int i = 0; i < 80; ++i) fill(G[i], G[i] + 80, 1000000);
  int n, k, nEdges;
  scanf("%d%d%d", &n, &k, &nEdges);
  for (int a, b, c; nEdges--;) {
    scanf("%d%d%d", &a, &b, &c);
    a--;
    b--;
    G[a][b] = min(G[a][b], c);
  }
  int ans = 1000000;
  for (int i = 0; i < n; ++i) ans = min(ans, go(0, i, n - 1, k));
  printf("%d\n", ans % 1000000 - 1);
  return 0;
}
