#include <bits/stdc++.h>
using namespace std;
int n, k, m;
vector<vector<pair<int, int>>> g;
unordered_map<int, int> cache;
inline int get_hash(int l, int r, int p, int o) {
  return l + r * 100 + o * 10000 + p * 1000000;
}
int get_ans(int l, int r, int p, int o) {
  ;
  if (o == 0) {
    return 0;
  }
  int hash = get_hash(l, r, p, o);
  if (cache.count(hash)) {
    return cache[hash];
  }
  if (p == 0) {
    p = l;
  } else {
    p = r;
  }
  int res = 1234567890;
  for (int(i) = (0); (i) < (int)(g[p].size()); ++(i)) {
    int c = g[p][i].first;
    int u = g[p][i].second;
    if (l <= u && u <= r && u != p) {
      ;
      res = min(res, c + min(get_ans(l + (p == l), u, 1, o - 1),
                             get_ans(u, r - (p == r), 0, o - 1)));
    }
  }
  cache[hash] = res;
  return res;
}
int main() {
  cin >> n >> k;
  cin >> m;
  --k;
  g.resize(n, vector<pair<int, int>>());
  for (int(i) = (0); (i) < (int)(m); ++(i)) {
    int u, v, c;
    cin >> u >> v >> c;
    u--, v--;
    g[u].push_back(make_pair(c, v));
  };
  int ans = min(get_ans(0, n - 1, 0, k), get_ans(0, n - 1, 1, k));
  for (int(i) = (0); (i) < (int)(n); ++(i)) {
    ans = min(ans, min(get_ans(0, i, 1, k), get_ans(i, n - 1, 0, k)));
  }
  cout << (ans == 1234567890 ? -1 : ans) << endl;
  return 0;
}
