#include <bits/stdc++.h>
using namespace std;
const int maxn = 81;
int n, m, k;
int dp[maxn][maxn][maxn][maxn];
int G[maxn][maxn];
int dfs(int u, int l, int r, int k) {
  if (dp[u][l][r][k] != -1) return dp[u][l][r][k];
  if (k == 1) return dp[u][l][r][k] = 0;
  if (l > r) return 0x3fffffff;
  int _min = 0x3fffffff;
  for (int i = l; i <= r; i++)
    if (G[u][i] < 0x3ffffff) {
      if (i > u)
        _min = min(_min, G[u][i] + dfs(i, u + 1, r, k - 1));
      else
        _min = min(_min, G[u][i] + dfs(i, l, u - 1, k - 1));
    }
  dp[u][l][r][k] = _min;
  return _min;
}
int main() {
  memset(dp, -1, sizeof dp);
  memset(G, 0x3f, sizeof G);
  scanf("%d%d", &n, &k);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    int u, v, dist;
    scanf("%d%d%d", &u, &v, &dist);
    G[u][v] = min(G[u][v], dist);
  }
  int _min = 0x3fffffff;
  for (int i = 1; i <= n; i++) {
    _min = min(_min, dfs(i, 1, n, k));
  }
  if (_min == 0x3fffffff)
    printf("-1\n");
  else
    printf("%d\n", _min);
  return 0;
}
