#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& s, vector<T> t) {
  for (int i = 0; i < (int)(t.size()); i++) s << (i ? " " : "") << t[i];
  return s;
}
template <typename T>
istream& operator>>(istream& s, vector<T>& t) {
  for (int i = 0; i < (int)(t.size()); i++) s >> t[i];
  return s;
}
template <typename T, typename U>
ostream& operator<<(ostream& s, pair<T, U> t) {
  s << "(" << t.first << "," << t.second << ")";
  return s;
}
template <typename T, typename U>
istream& operator>>(istream& s, pair<T, U>& t) {
  s >> t.first >> t.second;
  return s;
}
const int N = 90;
const int INF = 1e7;
int dp[N][N][N];
int c[N][N];
int main() {
  ios_base::sync_with_stdio(false);
  for (int i = 0; i < (int)(N); i++)
    for (int j = 0; j < (int)(N); j++) c[i][j] = INF;
  int n, k;
  cin >> n >> k;
  int m;
  cin >> m;
  for (int i = 0; i < (int)(m); i++) {
    int u, v, cc;
    cin >> u >> v >> cc;
    c[u][v] = min(c[u][v], cc);
  }
  n += 2;
  for (int ck = 1; ck < (int)(k); ck++) {
    for (int f = 0; f < (int)(n); f++)
      for (int t = 0; t < (int)(n); t++) {
        dp[ck][f][t] = INF;
        int mn = min(f, t);
        int mx = max(f, t);
        for (int j = mn + 1; j < (int)(mx); j++) {
          dp[ck][f][t] = min(dp[ck][f][t],
                             c[t][j] + min(dp[ck - 1][t][j], dp[ck - 1][f][j]));
        }
      }
  }
  int res = INF;
  for (int f = 0; f < (int)(n); f++)
    for (int t = 0; t < (int)(n); t++) res = min(res, dp[k - 1][f][t]);
  if (res == INF) res = -1;
  cout << res << endl;
}
