#include <bits/stdc++.h>
#pragma warning(disable : 4786)
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int maxn = 80 + 5;
int dp[maxn][maxn][maxn][2];
vector<pair<int, int> > G[maxn];
int dfs(int cur, int most, int k, int dir) {
  if (dp[cur][most][k][dir] != -1) return dp[cur][most][k][dir];
  if (dir == 0 && most > cur) return dp[cur][most][k][dir] = INF;
  if (dir == 1 && most < cur) return dp[cur][most][k][dir] = INF;
  if (k == 0) return dp[cur][most][k][dir] = 0;
  bool flag = false;
  dp[cur][most][k][dir] = INF;
  if (dir == 0) {
    for (int i = 0; i < G[cur].size(); i++) {
      int to = G[cur][i].first, cost = G[cur][i].second;
      if (to >= cur || to < most) continue;
      int next_jump = dfs(to, most, k - 1, 0);
      if (next_jump != INF) {
        flag = true;
        dp[cur][most][k][dir] = min(dp[cur][most][k][dir], next_jump + cost);
      }
      next_jump = dfs(to, cur - 1, k - 1, 1);
      if (next_jump != INF) {
        flag = true;
        dp[cur][most][k][dir] = min(dp[cur][most][k][dir], next_jump + cost);
      }
    }
  } else {
    for (int i = 0; i < G[cur].size(); i++) {
      int to = G[cur][i].first, cost = G[cur][i].second;
      if (to <= cur || to > most) continue;
      int next_jump = dfs(to, cur + 1, k - 1, 0);
      if (next_jump != INF) {
        flag = true;
        dp[cur][most][k][dir] = min(dp[cur][most][k][dir], next_jump + cost);
      }
      next_jump = dfs(to, most, k - 1, 1);
      if (next_jump != INF) {
        flag = true;
        dp[cur][most][k][dir] = min(dp[cur][most][k][dir], next_jump + cost);
      }
    }
  }
  if (!flag)
    return dp[cur][most][k][dir] = INF;
  else
    return dp[cur][most][k][dir];
}
int main() {
  memset(dp, -1, sizeof(dp));
  int n, m, u, v, k, c;
  scanf("%d %d %d", &n, &k, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d %d %d", &u, &v, &c);
    G[u].push_back(make_pair(v, c));
  }
  int ans = INF;
  for (int i = 1; i <= n; i++) {
    ans = min(ans, dfs(i, n, k - 1, 1));
    ans = min(ans, dfs(i, 1, k - 1, 0));
  }
  if (ans == INF) ans = -1;
  printf("%d\n", ans);
  return 0;
}
