#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
vector<pair<int, int> > edges[85];
int d[85][85];
int memo[85][85][85][85];
int dfs(int cur, int mn, int mx, int left) {
  if (memo[cur][mn][mx][left] != -1) return memo[cur][mn][mx][left];
  if (!left) return 0;
  int nxt, cost;
  int mnn = inf;
  for (int i = 0; i < edges[cur].size(); ++i) {
    nxt = edges[cur][i].first, cost = edges[cur][i].second;
    if (nxt > mn && nxt < mx) {
      if (nxt < cur) {
        mnn = min(mnn, cost + dfs(nxt, mn, min(mx, cur), left - 1));
      } else {
        mnn = min(mnn, cost + dfs(nxt, max(mn, cur), mx, left - 1));
      }
    }
  }
  return memo[cur][mn][mx][left] = mnn;
}
int main() {
  ios_base::sync_with_stdio(0);
  int n, k, m;
  int u, v, c;
  while (cin >> n >> k >> m) {
    memset(d, 0x3f, sizeof(d));
    for (int i = 0; i < m; ++i) {
      cin >> u >> v >> c;
      d[u][v] = min(d[u][v], c);
    }
    for (int u = 1; u <= n; ++u) {
      for (int v = 1; v <= n; ++v) {
        if (d[u][v] != inf) {
          edges[u].push_back(make_pair(v, d[u][v]));
        }
      }
    }
    memset(memo, -1, sizeof(memo));
    int res = inf;
    for (int i = 1; i <= n; ++i) {
      res = min(res, dfs(i, 0, n + 1, k - 1));
    }
    if (res < inf)
      cout << res << "\n";
    else
      cout << "-1\n";
    for (int i = 1; i <= n; ++i) edges[i].clear();
  }
  return 0;
}
