#include <bits/stdc++.h>
using namespace std;
int n, k, m;
vector<pair<int, int> > e[88];
int f[88][88][88][88];
inline void upd(int n, int l, int pos, int r, int val) {
  f[n][l][pos][r] = min(f[n][l][pos][r], val);
}
int main() {
  scanf("%d%d", &n, &k);
  scanf("%d", &m);
  for (int i = 0; i < m; ++i) {
    int first, second, w;
    scanf("%d%d%d", &first, &second, &w);
    --first;
    --second;
    if (first == second) continue;
    e[first].push_back(make_pair(second, w));
  }
  memset(f, 63, sizeof(f));
  for (int i = 0; i < n; ++i) f[1][n][i][n] = 0;
  int ans = 1000000000;
  for (int i = 1; i <= k; ++i) {
    for (int _l = 0; _l <= n; ++_l) {
      int l = _l;
      if (l == n) l = -1;
      for (int pos = l + 1; pos < n; ++pos) {
        for (int r = pos + 1; r <= n; ++r) {
          int val = f[i][_l][pos][r];
          if (val > 1000000000) continue;
          if (i == k) {
            ans = min(ans, val);
            continue;
          }
          for (int j = 0; j < (int)(e[pos]).size(); ++j) {
            int nxt = e[pos][j].first;
            if (nxt <= l || nxt >= r) continue;
            if (nxt < pos) {
              upd(i + 1, _l, nxt, pos, val + e[pos][j].second);
            } else {
              upd(i + 1, pos, nxt, r, val + e[pos][j].second);
            }
          }
        }
      }
    }
  }
  if (ans == 1000000000)
    cout << "-1\n";
  else
    cout << ans << endl;
}
