#include <bits/stdc++.h>
const long long INF = 4e18L + 1;
const int IINF = 2e9 + 1;
using namespace std;
template <class TH>
void _dbg(const char *sdbg, TH h) {
  cerr << sdbg << '=' << h << endl;
}
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << '=' << h << ',';
  _dbg(sdbg + 1, a...);
}
const int N = 80, K = 80;
int dpl[N + 2][N + 2][K + 1], dpr[N + 2][N + 2][K + 1];
int ed[N + 2][N + 2];
int n, k, m;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k >> m;
  for (long long i = (long long)0; i < (long long)n + 2; i++) {
    for (long long j = (long long)0; j < (long long)n + 2; j++) {
      ed[i][j] = 1e7;
    }
  }
  for (long long _ = (long long)0; _ < (long long)m; _++) {
    int u, v, c;
    cin >> u >> v >> c;
    ed[u][v] = min(ed[u][v], c);
  }
  for (long long ck = (long long)1; ck < (long long)k + 1; ck++) {
    for (long long i = (long long)0; i < (long long)n + 2; i++) {
      for (long long j = (long long)0; j < (long long)n + 2; j++) {
        dpl[i][j][ck] = 1e7;
        dpr[i][j][ck] = 1e7;
        for (long long mi = (long long)i + 1; mi < (long long)j; mi++) {
          dpl[i][j][ck] = min(dpl[i][j][ck], ed[i][mi] + dpr[i][mi][ck - 1]);
          dpl[i][j][ck] = min(dpl[i][j][ck], ed[i][mi] + dpl[mi][j][ck - 1]);
          dpr[i][j][ck] = min(dpr[i][j][ck], ed[j][mi] + dpl[mi][j][ck - 1]);
          dpr[i][j][ck] = min(dpr[i][j][ck], ed[j][mi] + dpr[i][mi][ck - 1]);
        }
      }
    }
  }
  int res = IINF;
  for (long long i = (long long)1; i < (long long)n + 1; i++) {
    res = min(res, dpl[i][n + 1][k - 1]);
    res = min(res, dpr[0][i][k - 1]);
  }
  if (res < 1e7) {
    cout << res << "\n";
  } else {
    cout << "-1\n";
  }
  return 0;
}
