#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:667772160")
struct debugger {
  template <typename T>
  debugger& operator,(const T& v) {
    cerr << v << " ";
    return *this;
  }
} dbg;
int dist[87][87];
int n, k;
int dp[82][82][82][82];
int rec(int now, int l, int r, int taken) {
  if (taken == k - 1) return 0;
  int& ret = dp[now][l][r][taken];
  if (ret != -1) return ret;
  ret = 1000000000LL;
  int temp;
  for (int i = now + 1; i < r; i++) {
    if (dist[now][i] != 1000000000LL) {
      temp = rec(i, now, r, taken + 1);
      if (temp + dist[now][i] < ret) ret = temp + dist[now][i];
    }
  }
  for (int i = now - 1; i > l; i--) {
    if (dist[now][i] != 1000000000LL) {
      temp = rec(i, l, now, taken + 1);
      if (temp + dist[now][i] < ret) ret = temp + dist[now][i];
    }
  }
  return ret;
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < 87; i++) {
    for (int j = 0; j < 87; j++) dist[i][j] = 1000000000LL;
  }
  int m, u, v, w;
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &u, &v);
    scanf("%d", &w);
    dist[u][v] = min(dist[u][v], w);
  }
  memset(dp, -1, sizeof(dp));
  int temp;
  int ans = 1000000000LL;
  for (int i = 1; i <= n; i++) {
    temp = rec(i, 0, n + 1, 0);
    ans = min(ans, temp);
  }
  if (ans == 1000000000LL)
    printf("-1\n");
  else
    printf("%d\n", ans);
  return 0;
}
