#include <bits/stdc++.h>
using namespace std;
const int N = 81;
const int INF = 0x3f3f3f3f;
template <typename T>
inline void read(T &AKNOI) {
  T x = 0, flag = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') flag = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  AKNOI = flag * x;
}
template <typename T>
inline void cmin(T &x, T y) {
  if (x > y) x = y;
}
template <typename T>
inline void cmax(T &x, T y) {
  if (x < y) x = y;
}
int n, K, m;
int g[N][N], dp[N][N][N][N];
int DP(int u, int k, int l, int r) {
  int &ret = dp[u][k][l][r];
  if (~ret) return ret;
  if (k == K) return ret = 0;
  ret = INF;
  for (int i = l; i <= r; ++i) {
    if (g[u][i] == INF) continue;
    int ll = l, rr = r;
    if (i < u) rr = u - 1;
    if (i > u) ll = u + 1;
    cmin(ret, DP(i, k + 1, ll, rr) + g[u][i]);
  }
  return ret;
}
void init() {
  read(n);
  read(K);
  read(m);
  memset(g, 0x3f, sizeof(g));
  for (int i = 1; i <= m; ++i) {
    int u, v, w;
    read(u);
    read(v);
    read(w);
    cmin(g[u][v], w);
  }
}
void solve() {
  memset(dp, -1, sizeof(dp));
  int ans = INF;
  for (int i = 1; i <= n; ++i) {
    cmin(ans, DP(i, 1, 1, n));
  }
  printf("%d\n", (ans < INF) ? ans : -1);
}
int main() {
  init();
  solve();
  return 0;
}
