#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
const int N = 88;
int n, K, m, u, v, c, dp[N][N][N][N];
vector<pair<int, int> > e[N];
void upd(int &a, int b) {
  if (a > b) a = b;
}
int main() {
  scanf("%d%d", &n, &K);
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &u, &v, &c);
    --u;
    --v;
    e[v].push_back(make_pair(u, c));
  }
  memset(dp, 0x20, sizeof(dp));
  for (int i = 0; i < n; i++) dp[0][i][i][i] = 0;
  for (int c = 0; c < K - 1; c++)
    for (int i = 0; i < n; i++)
      for (int mn = 0; mn < n; mn++)
        for (int mx = mn; mx < n; mx++)
          if (dp[c][i][mn][mx] <= 20000000) {
            assert(i == mn || i == mx);
            int r = dp[c][i][mn][mx];
            for (auto p : e[i])
              if (p.first < mn || p.first > mx)
                upd(dp[c + 1][p.first][min(mn, p.first)][max(mx, p.first)],
                    r + p.second);
          }
  int ans = 0x20202020;
  for (int i = 0; i < n; i++)
    for (int mn = 0; mn < n; mn++)
      for (int mx = mn; mx < n; mx++) ans = min(ans, dp[K - 1][i][mn][mx]);
  if (ans > 20000000) ans = -1;
  printf("%d\n", ans);
}
