#include <bits/stdc++.h>
using namespace std;
int g[82][82];
int dp[82][82][82][82];
int n, m, k;
int M_search(int l, int r, int cur, int k) {
  if (dp[l][r][cur][k] != -1) return dp[l][r][cur][k];
  if (k == 1) {
    dp[l][r][cur][k] = 0;
    return 0;
  }
  int ans = 0x7f7f7f7f;
  for (int i = 1; i <= n; i++) {
    if (g[cur][i] != 0x7f7f7f7f) {
      if (i > l && i < r) {
        if (i > cur)
          ans = min(ans, g[cur][i] + M_search(cur, r, i, k - 1));
        else
          ans = min(ans, g[cur][i] + M_search(l, cur, i, k - 1));
      }
    }
  }
  dp[l][r][cur][k] = ans;
  return dp[l][r][cur][k];
}
int main() {
  scanf("%d%d%d", &n, &k, &m);
  memset(dp, -1, sizeof(dp));
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) g[i][j] = 0x7f7f7f7f;
  for (int i = 1; i <= m; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    g[u][v] = min(g[u][v], w);
  }
  int ans = 0x7f7f7f7f;
  for (int i = 1; i <= n; i++) ans = min(ans, M_search(0, n + 1, i, k));
  if (ans >= 0x7f7f7f7f) ans = -1;
  printf("%d\n", ans);
  return 0;
}
