#include <bits/stdc++.h>
int t1, t2, t3;
int g[88][88];
int n, k;
int m;
int dp[88][88][88];
int ans = 0x3f3f3f3f;
int main() {
  scanf("%d%d", &n, &k);
  scanf("%d", &m);
  for (int i = 0; i <= n + 1; i++) {
    for (int j = 0; j <= n + 1; j++) {
      g[i][j] = 0x3f3f3f3f;
      for (int kk = 0; kk <= k; kk++) dp[i][j][kk] = 0x3f3f3f3f;
    }
  }
  while (m--) {
    scanf("%d%d%d", &t1, &t2, &t3);
    g[t1][t2] = (g[t1][t2] <= t3 ? g[t1][t2] : t3);
  }
  for (int i = 1; i <= n; i++) {
    dp[i][0][1] = 0;
    dp[i][n + 1][1] = 0;
  }
  for (int diff = n; diff > 0; diff--) {
    for (int i = 1; i <= n; i++) {
      if (i + diff > n + 1) continue;
      for (int kk = 0; kk < k; kk++) {
        if (dp[i][i + diff][kk] == 0x3f3f3f3f) continue;
        for (int j = i + 1; j < i + diff; j++) {
          if (g[i][j] == 0x3f3f3f3f) continue;
          dp[j][i + diff][kk + 1] =
              (dp[j][i + diff][kk + 1] <= dp[i][i + diff][kk] + g[i][j]
                   ? dp[j][i + diff][kk + 1]
                   : dp[i][i + diff][kk] + g[i][j]);
          dp[j][i][kk + 1] = (dp[j][i][kk + 1] <= dp[i][i + diff][kk] + g[i][j]
                                  ? dp[j][i][kk + 1]
                                  : dp[i][i + diff][kk] + g[i][j]);
        }
      }
    }
    for (int i = 1; i <= n; i++) {
      if (i - diff < 0) continue;
      for (int kk = 0; kk < k; kk++) {
        if (dp[i][i - diff][kk] == 0x3f3f3f3f) continue;
        for (int j = i - 1; j > i - diff; j--) {
          if (g[i][j] == 0x3f3f3f3f) continue;
          dp[j][i - diff][kk + 1] =
              (dp[j][i - diff][kk + 1] <= dp[i][i - diff][kk] + g[i][j]
                   ? dp[j][i - diff][kk + 1]
                   : dp[i][i - diff][kk] + g[i][j]);
          dp[j][i][kk + 1] = (dp[j][i][kk + 1] <= dp[i][i - diff][kk] + g[i][j]
                                  ? dp[j][i][kk + 1]
                                  : dp[i][i - diff][kk] + g[i][j]);
        }
      }
    }
  }
  for (int i = 0; i <= n + 1; i++) {
    for (int j = 0; j <= n + 1; j++) {
      ans = (ans <= dp[i][j][k] ? ans : dp[i][j][k]);
    }
  }
  if (ans == 0x3f3f3f3f)
    printf("-1");
  else
    printf("%d", ans);
}
