#include <bits/stdc++.h>
using namespace std;
int n, k;
int m;
vector<pair<int, int> > g[81];
int minut[81][81];
int dp[81][81][81][81];
long long mini = INT_MAX;
long long rek(int l, int r, int mid, int more) {
  if (more == 0) return 0;
  if (dp[l][r][mid][more] != 0) return dp[l][r][mid][more];
  long long akt = INT_MAX;
  for (auto s : g[mid]) {
    if (s.first <= l || s.first >= r) continue;
    if (s.first > mid)
      akt = min(akt, s.second + rek(mid, r, s.first, more - 1));
    else
      akt = min(akt, s.second + rek(l, mid, s.first, more - 1));
  }
  dp[l][r][mid][more] = akt;
  return akt;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> k;
  cin >> m;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) minut[i][j] = INT_MAX;
  }
  for (int i = 1; i <= m; i++) {
    int k, v, c;
    cin >> k >> v >> c;
    minut[k][v] = min(minut[k][v], c);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (minut[i][j] != INT_MAX) g[i].push_back({j, minut[i][j]});
    }
  }
  for (int i = 1; i <= n; i++) {
    mini = min(mini, rek(0, n + 1, i, k - 1));
  }
  if (mini == INT_MAX)
    cout << -1;
  else
    cout << mini;
  return 0;
}
