#include <bits/stdc++.h>
using namespace std;
void func(void) {
  freopen("input.c", "r", stdin);
  freopen("output.c", "w", stdout);
}
void print(vector<long long> &v) {
  cout << v.size() << endl;
  for (int i = 0; i < v.size(); i++) {
    printf("%lld ", v[i]);
  }
  printf("\n");
}
void print(vector<pair<long long, long long> > &v) {
  cout << v.size() << endl;
  for (int i = 0; i < v.size(); i++) {
    printf("%lld %lld\n", v[i].first, v[i].second);
  }
}
void print(double d) { cout << fixed << setprecision(10) << d << endl; }
void print(string s, double d) {
  cout << s << " ";
  cout << fixed << setprecision(10) << d << endl;
}
int dp[82][82][82][82];
const int N = 82;
vector<pair<int, int> > a[82];
int calc(int cnt, int to, int from, int now) {
  if (cnt == 0) {
    return 0;
  }
  if (dp[cnt][to][from][now] != -1) {
    return dp[cnt][to][from][now];
  }
  int x = 1e7;
  for (pair<int, int> y : a[now]) {
    if (to < y.first and y.first < now) {
      x = min(x, y.second + calc(cnt - 1, to, now, y.first));
    }
    if (now < y.first and y.first < from) {
      x = min(x, y.second + calc(cnt - 1, now, from, y.first));
    }
  }
  return dp[cnt][to][from][now] = x;
}
int main() {
  long long n, q, i, j = 0, temp, t, k, ans = 0, sum = 0, x, y, z, cnt = 0, m,
                     fg = 0, mx = 0, mx1 = 0, mn = 8000000000000000000,
                     mn1 = 8000000000000000000;
  scanf("%lld %lld %lld", &n, &k, &m);
  while (m--) {
    scanf("%lld %lld %lld", &x, &y, &z);
    a[x].push_back({y, z});
  }
  memset((dp), -1, sizeof(dp));
  int mini = 1e7;
  for (int i = 1; i <= n; i++) {
    mini = min(mini, calc(k - 1, 0, n + 1, i));
  }
  if (mini > 1e5) mini = -1;
  cout << mini << endl;
}
