#include <bits/stdc++.h>
using namespace std;
const int N = 80, oo = 1e9;
vector<pair<int, int>> g[N];
int n, k, m, dp[N][N][N][N];
int calc(int curr, int l, int r, int k) {
  if (k == 0) return 0;
  int &ans = dp[curr][l][r][k];
  if (ans > -1) return ans;
  ans = oo;
  for (int i = 0; i < g[curr].size(); i++) {
    int d = g[curr][i].first, cost = g[curr][i].second;
    if (d >= l && d <= r && d > curr)
      ans = min(ans, cost + calc(d, curr + 1, r, k - 1));
    else if (d >= l && d <= r && d < curr)
      ans = min(ans, cost + calc(d, l, curr - 1, k - 1));
  }
  return ans;
}
int main() {
  memset(dp, -1, sizeof(dp));
  scanf("%d%d%d", &n, &k, &m);
  int ans = oo;
  for (int i = 0, a, b, c; i < m; i++) {
    scanf("%d%d%d", &a, &b, &c);
    --a, --b;
    g[a].push_back({b, c});
  }
  for (int i = 0; i < n; i++) ans = min(ans, calc(i, 0, n - 1, k - 1));
  if (ans == oo) return cout << -1 << endl, 0;
  cout << ans << endl;
  return 0;
}
