#include <bits/stdc++.h>
using namespace std;
const int N = 90, INF = 1e9 + 7;
int n, m, k, c[N][N], d[N][N][N], ans;
vector<int> a[N];
priority_queue<pair<pair<int, int>, pair<int, int> > > pq;
void Dijkstra(int S) {
  for (int i = (1); i <= (n); i++)
    for (int i1 = (0); i1 <= (n); i1++)
      for (int i2 = (0); i2 <= (n); i2++) d[i][i1][i2] = INF;
  d[S][0][k - 1] = 0;
  pq.push(pair<pair<int, int>, pair<int, int> >(pair<int, int>(0, S),
                                                pair<int, int>(0, k - 1)));
  while (!pq.empty()) {
    int du = -pq.top().first.first, u = pq.top().first.second;
    int u1 = pq.top().second.first, re = pq.top().second.second;
    pq.pop();
    if (du != d[u][u1][re]) continue;
    if (re == 0) continue;
    for (int i = 0; i < (int((a[u]).size())); i++) {
      int v = a[u][i];
      int c1 = d[u][u1][re] + c[u][v];
      if (!u1 || (u > u1 && u1 > v) || (u < u1 && u1 < v)) {
        if (d[v][u][re - 1] > c1) {
          d[v][u][re - 1] = c1;
          pq.push(pair<pair<int, int>, pair<int, int> >(
              pair<int, int>(-c1, v), pair<int, int>(u, re - 1)));
        }
      } else if ((u1 < u && u < v) || (u1 > u && u > v)) {
        if (u1 && d[v][u1][re - 1] > c1) {
          d[v][u1][re - 1] = c1;
          pq.push(pair<pair<int, int>, pair<int, int> >(
              pair<int, int>(-c1, v), pair<int, int>(u1, re - 1)));
        }
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k >> m;
  for (int i = (1); i <= (m); i++) {
    int u, v, c1;
    cin >> u >> v >> c1;
    if (!c[v][u]) {
      a[v].push_back(u);
      c[v][u] = c1;
    } else
      c[v][u] = min(c[v][u], c1);
  }
  ans = INF;
  for (int i = (1); i <= (n); i++) {
    Dijkstra(i);
    for (int j = (1); j <= (n); j++)
      for (int j1 = (0); j1 <= (n); j1++) ans = min(ans, d[j][j1][0]);
  }
  if (ans == INF)
    cout << -1;
  else
    cout << ans;
  return 0;
}
