#include <bits/stdc++.h>
using namespace std;
const int oo = 2e9;
const int maxn = 81;
int dp[maxn][maxn][maxn][maxn], n, m, k, a, b, c, ans = oo;
vector<pair<int, int> > adj[maxn];
int main() {
  cin >> n >> k >> m;
  while (m--) {
    cin >> a >> b >> c;
    adj[a].push_back({b, c});
  }
  for (int i = 2; i <= k; ++i)
    for (int lr = 1; lr <= n; ++lr) dp[i][lr][lr][lr] = oo;
  for (int i = 2; i <= k; ++i)
    for (int l = 1; l < n; ++l)
      for (int r = l + 1; r <= n; ++r)
        for (int v = l; v <= r; ++v) {
          dp[i][l][r][v] = oo;
          for (auto j : adj[v])
            if (j.first >= l && j.first <= r)
              dp[i][l][r][v] =
                  min(dp[i][l][r][v], dp[i - 1][j.first < v ? l : v + 1]
                                        [j.first < v ? v - 1 : r][j.first] +
                                          j.second);
        }
  for (int i = 1; i <= n; ++i) ans = min(ans, dp[k][1][n][i]);
  if (ans == oo)
    cout << -1 << '\n';
  else
    cout << ans << '\n';
  return 0;
}
