#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > maps[88];
int n, kk, m, maxs = 987654321;
int arr[88], ff, ss, vis[88][88][88][88];
int dfs(int now, int k, int ff, int ss) {
  if (k == kk) return 0;
  if (vis[k][ff][ss][now] != -1) return vis[k][ff][ss][now];
  int sz = maps[now].size();
  int mn = 987654321;
  for (int e = 0; e < sz; e++) {
    int next = maps[now][e].first, dist = maps[now][e].second;
    if (next > ff && next < ss) {
      if (next < now) mn = min(mn, dfs(next, k + 1, ff, now) + dist);
      if (next > now) mn = min(mn, dfs(next, k + 1, now, ss) + dist);
    }
  }
  vis[k][ff][ss][now] = mn;
  return mn;
}
int main(void) {
  scanf("%d%d%d", &n, &kk, &m);
  for (int e = 0; e < m; e++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    maps[a].push_back({b, c});
  }
  memset(vis, -1, sizeof(vis));
  for (int e = 1; e <= n; e++) {
    maxs = min(maxs, dfs(e, 1, 0, 81));
  }
  if (maxs == 987654321)
    printf("-1");
  else
    printf("%d", maxs);
}
