#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-5;
int value[85][85];
int dp[85][85][85][2];
int main() {
  memset(value, 0x3f3f3f3f, sizeof(value));
  int n, k, m;
  scanf("%d%d%d", &n, &k, &m);
  for (int i = 0; i < m; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    value[u][v] = min(value[u][v], w);
  }
  memset(dp, 0x3f3f3f3f, sizeof(dp));
  for (int i = 1; i <= n; i++) dp[i][i][1][0] = dp[i][i][1][1] = 0;
  for (int i = 1; i < n; i++) {
    for (int j = 1; j + i <= n; j++) {
      for (int kk = j; kk < j + i; kk++) {
        if (value[i + j][j] != 0x3f3f3f3f)
          for (int l = 2; l <= k; l++)
            dp[j][i + j][l][1] =
                min(dp[j][i + j][l][1], dp[j][kk][l - 1][0] + value[i + j][j]);
        if (value[i + j][kk] != 0x3f3f3f3f)
          for (int l = 2; l <= k; l++)
            dp[j][i + j][l][1] =
                min(dp[j][i + j][l][1], dp[j][kk][l - 1][1] + value[i + j][kk]);
      }
      for (int kk = j + 1; kk <= j + i; kk++) {
        if (value[j][i + j] != 0x3f3f3f3f)
          for (int l = 2; l <= k; l++)
            dp[j][i + j][l][0] = min(dp[j][i + j][l][0],
                                     dp[kk][j + i][l - 1][1] + value[j][j + i]);
        if (value[j][kk] != 0x3f3f3f3f)
          for (int l = 2; l <= k; l++)
            dp[j][i + j][l][0] =
                min(dp[j][i + j][l][0], dp[kk][j + i][l - 1][0] + value[j][kk]);
      }
    }
  }
  int ans = 0x3f3f3f3f;
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      ans = min(ans, dp[i][j][k][0]);
      ans = min(ans, dp[i][j][k][1]);
    }
  }
  if (ans == 0x3f3f3f3f) ans = -1;
  printf("%d\n", ans);
}
