#include <bits/stdc++.h>
using namespace std;
int n, k;
int diff[85][85];
int dp[85][85][85];
int main() {
  scanf("%d%d", &(n), &(k));
  ;
  int(m);
  scanf("%d", &(m));
  ;
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (n); ++j) diff[i][j] = 1e9;
  for (int i = (0); i < (m); ++i) {
    int(a), (b), (c);
    scanf("%d%d%d", &(a), &(b), &(c));
    ;
    a--;
    b--;
    diff[a][b] = min(diff[a][b], c);
  }
  for (int i = (0); i < (n); ++i) diff[i][i] = 1e9;
  if (k == 1) {
    printf("0\n");
    return 0;
  }
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (n); ++j) {
      dp[i][j][2] = 1e9;
      int a = min(i, j);
      int b = max(i, j);
      for (int u = (a); u < (b + 1); ++u) {
        dp[i][j][2] = min(dp[i][j][2], diff[i][u]);
      }
    }
  for (int l = (3); l < (k + 1); ++l) {
    for (int i = (0); i < (n); ++i)
      for (int j = (0); j < (n); ++j) dp[i][j][l] = 1e9;
    for (int i = (0); i < (n); ++i)
      for (int j = (0); j < (n); ++j) {
        if (i < j) {
          for (int u = (i + 1); u < (j + 1); ++u) {
            dp[i][j][l] = min(dp[i][j][l], diff[i][u] + dp[u][i + 1][l - 1]);
            dp[i][j][l] = min(dp[i][j][l], diff[i][u] + dp[u][j][l - 1]);
          }
        }
        if (j < i) {
          for (int u = (j); u < (i); ++u) {
            dp[i][j][l] = min(dp[i][j][l], diff[i][u] + dp[u][i - 1][l - 1]);
            dp[i][j][l] = min(dp[i][j][l], diff[i][u] + dp[u][j][l - 1]);
          }
        }
      }
  }
  int best = 1e9;
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (n); ++j) best = min(best, dp[i][j][k]);
  if (best == 1e9)
    printf("-1\n");
  else
    printf("%d\n", best);
}
