#include <bits/stdc++.h>
using namespace std;
void FREOPEN() {
  freopen(
      ""
      ".in",
      "r", stdin);
  freopen(
      ""
      ".out",
      "w", stdout);
}
inline double Time() { return (clock() * 1.0) / CLOCKS_PER_SEC; }
const int N = 83, inf = 1e9 * 2, MOD = 1e9 + 7;
char CH[N];
const long long INF = 1e18;
const int dx[] = {1, -1, 0, 0, -1, 1, -1, 1};
const int dy[] = {0, 0, 1, -1, -1, 1, 1, -1};
int dp[N][N][N][N];
vector<pair<int, int> > g[N];
int main() {
  int n, k;
  cin >> n >> k;
  int m;
  cin >> m;
  for (int i = 1; i <= m; i++) {
    int x, y, w;
    scanf("%d %d %d", &x, &y, &w);
    g[x].push_back({y, w});
  }
  for (int i = 1; i <= k; i++) {
    for (int l = 0; l <= n + 1; l++) {
      for (int r = 0; r <= n + 1; r++) {
        for (int v = 1; v <= n; v++) dp[i][v][l][r] = inf;
      }
    }
  }
  for (int v = 1; v <= n; v++) dp[1][v][0][n + 1] = 0;
  for (int i = 1; i < k; i++) {
    for (int v = 1; v <= n; v++) {
      for (int l = 0; l < v; l++) {
        for (int r = v + 1; r <= n + 1; r++) {
          if (dp[i][v][l][r] == inf) continue;
          for (auto kk : g[v]) {
            int u = kk.first;
            int len = kk.second;
            if (u <= l || u >= r) continue;
            if (u < v)
              dp[i + 1][u][l][v] =
                  min(dp[i + 1][u][l][v], dp[i][v][l][r] + len);
            else
              dp[i + 1][u][v][r] =
                  min(dp[i + 1][u][v][r], dp[i][v][l][r] + len);
          }
        }
      }
    }
  }
  int ans = inf;
  for (int v = 1; v <= n; v++) {
    for (int l = 0; l < v; l++) {
      for (int r = v + 1; r <= n + 1; r++) {
        ans = min(ans, dp[k][v][l][r]);
      }
    }
  }
  if (ans == inf) ans = -1;
  cout << ans;
  return 0;
}
