#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d, i, e, f, g, n, m, k, l, minn, dp[83][83][83];
vector<pair<long long, long long> > v[83];
int main() {
  cin >> n >> k >> m;
  k--;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 0; j <= n + 1; j++) {
      for (long long o = 1; o <= k; o++) {
        dp[i][j][o] = 1e18;
      }
    }
  }
  for (long long i = 1; i <= m; i++) {
    cin >> a >> b >> c;
    v[a].push_back({b, c});
    dp[b][a][1] = min(c, dp[b][a][1]);
    if (a > b)
      dp[b][0][1] = min(c, dp[b][0][1]);
    else
      dp[b][n + 1][1] = min(c, dp[b][n + 1][1]);
  }
  for (long long i = 2; i <= k; i++) {
    for (long long j = 0; j <= n + 1; j++) {
      for (long long o = 1; o <= n; o++) {
        if (dp[o][j][i - 1] == 1e18) continue;
        for (long long r = 0; r < v[o].size(); r++) {
          if (min(j, o) < v[o][r].first && v[o][r].first < max(j, o)) {
            dp[v[o][r].first][o][i] =
                min(dp[v[o][r].first][o][i], v[o][r].second + dp[o][j][i - 1]);
            dp[v[o][r].first][j][i] =
                min(dp[v[o][r].first][j][i], v[o][r].second + dp[o][j][i - 1]);
          }
        }
      }
    }
  }
  minn = 1e18;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 1; j <= n; j++) {
      minn = min(minn, dp[i][j][k]);
    }
  }
  if (minn == 1e18)
    cout << -1;
  else
    cout << minn;
}
