#include <bits/stdc++.h>
using namespace std;
const int M = 82, INF = 0x3f3f3f3f;
int n, K;
int w[M][M];
int dp[M][M][M][M];
void dec(int& x, int y) {
  if (x > y) x = y;
}
int dfs(int L, int i, int R, int k) {
  int& x = dp[L][i][R][k];
  if (x != -1) return x;
  if (k == 0) return x = 0;
  x = INF;
  for (int j = L + 1; j < i; j++) {
    dec(x, w[i][j] + dfs(L, j, i, k - 1));
  }
  for (int j = i + 1; j < R; j++) {
    dec(x, w[i][j] + dfs(i, j, R, k - 1));
  }
  return x;
}
int main() {
  scanf("%d%d", &n, &K);
  if (K > n) {
    printf("%d\n", -1);
    return 0;
  }
  int m;
  scanf("%d", &m);
  memset(w, 0x3f, sizeof w);
  memset(dp, -1, sizeof dp);
  for (int i = 1; i <= m; i++) {
    int u, v, c;
    scanf("%d%d%d", &u, &v, &c);
    dec(w[u][v], c);
  }
  int ans = INF;
  for (int i = 1; i <= n; i++) {
    dec(ans, dfs(0, i, n + 1, K - 1));
  }
  if (ans >= INF) ans = -1;
  printf("%d\n", ans);
}
