#include <bits/stdc++.h>
using namespace std;
void read(bool out = 0) {}
long long dp[100][100][100][2];
vector<vector<pair<long long, long long> > > ad;
int k;
long long ans(long long st, long long en, long long num, bool type) {
  if (num == k)
    return 0;
  else if (en < st)
    return 1e15;
  if (dp[st][en][num][type] == -1) {
    long long u = type ? en + 1 : st - 1;
    long long tmp = 1e15;
    for (int i = 0; i < ad[u].size(); i++) {
      long long v = ad[u][i].first;
      long long w = ad[u][i].second;
      if (v >= st && v <= en) {
        if (type == 0) {
          tmp = min(tmp, w + min(ans(st, v - 1, num + 1, 1),
                                 ans(v + 1, en, num + 1, 0)));
        } else {
          tmp = min(tmp, w + min(ans(v + 1, en, num + 1, 0),
                                 ans(st, v - 1, num + 1, 1)));
        }
      }
    }
    dp[st][en][num][type] = tmp;
  }
  return dp[st][en][num][type];
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  read();
  int n;
  cin >> n;
  cin >> k;
  memset(dp, -1, sizeof dp);
  long long m;
  cin >> m;
  ad = vector<vector<pair<long long, long long> > >(n + 1);
  while (m--) {
    long long x, y, w;
    cin >> x >> y >> w;
    x--, y--;
    if (x != y) ad[x].push_back(make_pair(y, w));
  }
  long long sol = 1e15;
  for (int i = 0; i < n; i++) {
    sol = min(sol, ans(i + 1, n - 1, 1, 0));
    sol = min(sol, ans(0, i - 1, 1, 1));
  }
  if (sol >= 1e15)
    cout << -1;
  else
    cout << sol;
}
