#include <bits/stdc++.h>
using namespace std;
int n, k, m, ans = 1 << 30;
int ma[85][85];
int dp[85][85][85][85];
int dfs(int pos, int step, int l, int r) {
  if (dp[l][r][pos][step] != -1) return dp[l][r][pos][step];
  if (step == 1) return dp[l][r][pos][step] = 0;
  for (int i = 1; i <= n; i++) {
    if (ma[pos][i] != 1 << 30 && i > l && i < r) {
      int zuo = l, you = r;
      if (i > pos)
        zuo = pos;
      else
        you = pos;
      int rnt = dfs(i, step - 1, zuo, you);
      if (dp[l][r][pos][step] > 0)
        dp[l][r][pos][step] = min(rnt + ma[pos][i], dp[l][r][pos][step]);
      else
        dp[l][r][pos][step] = rnt + ma[pos][i];
    }
  }
  if (dp[l][r][pos][step] > 0) return dp[l][r][pos][step];
  return 1 << 30;
}
int main() {
  scanf("%d%d%d", &n, &k, &m);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) ma[i][j] = 1 << 30;
  memset(dp, -1, sizeof(dp));
  for (int x, y, z, i = 1; i <= m; i++) {
    scanf("%d%d%d", &x, &y, &z);
    ma[x][y] = min(ma[x][y], z);
  }
  for (int i = 1; i <= n; i++) ans = min(ans, dfs(i, k, 0, n + 1));
  if (ans == 1 << 30)
    printf("-1\n");
  else
    printf("%d\n", ans);
  return 0;
}
