#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
constexpr int MAX = 128;
constexpr int INF = 0x3F3F3F3F;
int mat[MAX][MAX], dp[MAX][MAX][MAX][2];
int DFS(int l, int r, int k, int d) {
  if (r - l < k) return INF;
  if (!k) return 0;
  if (~dp[l][r][k][d]) return dp[l][r][k][d];
  int& ret = dp[l][r][k][d];
  ret = INF;
  for (int i = l; i <= r; ++i) {
    if (!d && mat[l][i] < INF) {
      int u = DFS(l + 1, i, k - 1, 1);
      int v = DFS(i, r, k - 1, 0);
      ret = min(ret, min(u, v) + mat[l][i]);
    }
    if (d && mat[r][i] < INF) {
      int u = DFS(l, i, k - 1, 1);
      int v = DFS(i, r - 1, k - 1, 0);
      ret = min(ret, min(u, v) + mat[r][i]);
    }
  }
  return ret;
}
int Solve(int n, int k) {
  memset(dp, -1, sizeof(dp));
  int ret = INF;
  for (int i = 0; i < n; ++i) {
    for (int j = i; j < n; ++j) {
      ret = min(ret, min(DFS(i, j, k - 1, 0), DFS(i, j, k - 1, 1)));
    }
  }
  return ret < INF ? ret : -1;
}
int main() {
  int n, m, k;
  while (~scanf("%d%d", &n, &k)) {
    memset(mat, 0x3F, sizeof(mat));
    scanf("%d", &m);
    int a, b, c;
    for (int i = 0; i < m; ++i) {
      scanf("%d%d%d", &a, &b, &c);
      mat[a - 1][b - 1] = min(mat[a - 1][b - 1], c);
    }
    printf("%d\n", Solve(n, k));
  }
  return 0;
}
