#include <bits/stdc++.h>
using namespace std;
int dis[82][82][82][82];
bool vis[82][82][82][82];
struct EDGE {
  int to, next, len;
  EDGE(int to = 0, int next = 0, int len = 0) : to(to), next(next), len(len) {}
} edge[4096];
struct node {
  int dis, left, right, now, k;
  node(int dis, int left, int right, int now, int k)
      : dis(dis), left(left), right(right), now(now), k(k) {}
  bool operator<(const node &b) const { return dis > b.dis; }
};
int head[81], edgecnt;
void init() {
  memset(head, -1, sizeof(head));
  edgecnt = 0;
  memset(dis, 0x7F, sizeof(dis));
  memset(vis, 0, sizeof(vis));
}
void add(int s, int t, int l) {
  edge[edgecnt] = EDGE(t, head[s], l);
  head[s] = edgecnt++;
}
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  init();
  int m;
  scanf("%d", &m);
  while (m--) {
    int s, t, l;
    scanf("%d %d %d", &s, &t, &l);
    add(s, t, l);
  }
  priority_queue<node> q;
  for (int i = 1; i <= n; i++) {
    q.push(node(0, 0, n + 1, i, 0));
    dis[0][n + 1][i][0] = 0;
  }
  while (!q.empty()) {
    node x = q.top();
    q.pop();
    if (x.k == k - 1) {
      printf("%d\n", x.dis);
      return 0;
    }
    if (vis[x.left][x.right][x.now][x.k]) continue;
    vis[x.left][x.right][x.now][x.k] = 1;
    for (int i = head[x.now]; ~i; i = edge[i].next) {
      int v = edge[i].to;
      if (v <= x.left || v >= x.right) continue;
      int L, R, now = v, kk = x.k + 1;
      if (v < x.now) {
        L = x.left;
        R = x.now;
      } else {
        L = x.now;
        R = x.right;
      }
      int dd = dis[x.left][x.right][x.now][x.k] + edge[i].len;
      if (dis[L][R][now][kk] > dd) {
        dis[L][R][now][kk] = dd;
        q.push(node(dd, L, R, now, kk));
      }
    }
  }
  printf("-1\n");
  return 0;
}
