#include <bits/stdc++.h>
using namespace std;
const int inf = 1e5 + 7;
int dp[81][81][81][82];
vector<pair<int, int> > g[81];
int f(int pos, int q, int l, int r) {
  if (q == 0) return 0;
  if (dp[pos][q][l][r] == 0) {
    dp[pos][q][l][r] = inf;
    for (auto to : g[pos])
      if (to.first > l && to.first < r)
        if (to.first > pos)
          dp[pos][q][l][r] =
              min(dp[pos][q][l][r], to.second + f(to.first, q - 1, pos, r));
        else
          dp[pos][q][l][r] =
              min(dp[pos][q][l][r], to.second + f(to.first, q - 1, l, pos));
  }
  return dp[pos][q][l][r];
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m, k;
  cin >> n >> k >> m;
  while (m--) {
    int a, b, c;
    cin >> a >> b >> c;
    g[a].push_back({b, c});
  }
  int res = inf;
  for (int i = 1; i <= n; ++i) res = min(res, f(i, k - 1, 0, n + 1));
  if (res > n * 1000)
    cout << "-1\n";
  else
    cout << res << "\n";
  return 0;
}
