#include <bits/stdc++.h>
using namespace std;
const int MAXN = 88, oo = 1000000000;
int N, K, M;
int dist[MAXN][MAXN];
int dp[MAXN][MAXN][MAXN][2];
int DP(int a, int b, int k, int p) {
  if (k == K) {
    return 0;
  }
  int& res = dp[a][b][k][p];
  if (res != -1) {
    return res;
  }
  res = oo;
  if (p == 0) {
    for (int c = a + 1; c <= b; c++) {
      res = min(res,
                dist[a][c] + min(DP(a + 1, c, k + 1, 1), DP(c, b, k + 1, 0)));
    }
  } else {
    for (int c = a; c < b; c++) {
      res = min(res,
                dist[b][c] + min(DP(a, c, k + 1, 1), DP(c, b - 1, k + 1, 0)));
    }
  }
  return res;
}
int main() {
  scanf("%d %d", &N, &K);
  scanf("%d", &M);
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++) {
      dist[i][j] = oo;
    }
  for (int i = 0; i < M; i++) {
    int u, v, c;
    scanf("%d %d %d", &u, &v, &c);
    u--, v--;
    dist[u][v] = min(dist[u][v], c);
  }
  memset(dp, -1, sizeof dp);
  int res = DP(0, N, 0, 1);
  if (res == oo) {
    res = -1;
  }
  printf("%d\n", res);
}
