#include <bits/stdc++.h>
using namespace std;
const int N = 82;
int dist[N][N][N][N];
vector<pair<int, int> > adj[N];
struct State {
  int dist;
  int u, k, i, j;
  bool operator<(const State& rhs) const { return dist > rhs.dist; }
};
int main() {
  int n, K;
  scanf("%d%d", &n, &K);
  int m;
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    int u, v, cost;
    scanf("%d%d%d", &u, &v, &cost);
    if (u == v) continue;
    adj[u].push_back({v, cost});
  }
  memset(dist, 0x3f, sizeof dist);
  priority_queue<State> pq;
  for (int i = 1; i <= n; i++) {
    dist[i][0][0][n + 1] = 0;
    pq.push({0, i, 0, 0, n + 1});
  }
  while (!pq.empty()) {
    State cur = pq.top();
    pq.pop();
    if (cur.dist != dist[cur.u][cur.k][cur.i][cur.j]) continue;
    if (cur.k == K - 1) {
      cout << cur.dist << endl;
      return 0;
    }
    for (auto& e : adj[cur.u]) {
      if (e.first <= cur.i || e.first >= cur.j) continue;
      if (e.first > cur.u) {
        if (cur.dist + e.second < dist[e.first][cur.k + 1][cur.u][cur.j]) {
          dist[e.first][cur.k + 1][cur.u][cur.j] = cur.dist + e.second,
                                pq.push({cur.dist + e.second, e.first,
                                         cur.k + 1, cur.u, cur.j});
        }
      } else {
        if (cur.dist + e.second < dist[e.first][cur.k + 1][cur.i][cur.u])
          dist[e.first][cur.k + 1][cur.i][cur.u] = cur.dist + e.second,
                                pq.push({cur.dist + e.second, e.first,
                                         cur.k + 1, cur.i, cur.u});
      }
    }
  }
  cout << -1 << endl;
}
