#include <bits/stdc++.h>
using namespace std;
void rd(int &x) { scanf("%d", &x); }
void rd(int &x, int &y) { scanf("%d%d", &x, &y); }
void rd(int &x, int &y, int &z) { scanf("%d%d%d", &x, &y, &z); }
void rd(int &x, int &y, int &z, int &s) { scanf("%d%d%d%d", &x, &y, &z, &s); }
struct debugger {
  template <class T>
  debugger &operator,(const T &v) {
    cerr << v << " ";
    return *this;
  }
} dbg;
void debugv(vector<long long> vec) {
  cerr << "printing vector:: ";
  for (int i = 0; i < (vec.size()); i++) {
    cout << vec[i] << " ";
  }
  cerr << endl;
}
void debugs(set<long long> s) {
  cerr << "printing set:: ";
  for (auto it = s.begin(); it != s.end(); it++) {
    cout << (*it) << " ";
  }
  cerr << endl;
}
int n, k, m, dis[81][81];
int dp[81][81][81][81];
int back(long long l, long long r, long long cur, long long p) {
  if (p == k) return 0;
  int &x = dp[l][r][cur][p];
  if (x != -1) return x;
  int ret = 1e8 + 5;
  for (int i = l; i <= r; i++) {
    if (i != cur && dis[cur][i] < 1e8 + 5) {
      if (i < cur)
        ret = min(ret, back(l, cur - 1, i, p + 1) + dis[cur][i]);
      else
        ret = min(ret, back(cur + 1, r, i, p + 1) + dis[cur][i]);
    }
  }
  return x = ret;
}
int main() {
  rd(n, k, m);
  for (int i = 1; i <= (n); i++) {
    for (int w = 1; w <= (n); w++) dis[i][w] = 1e8 + 5;
  }
  for (int i = 1; i <= (m); i++) {
    int u, v, c;
    rd(u, v, c);
    dis[u][v] = min(dis[u][v], c);
  }
  memset((dp), -1, sizeof((dp)));
  int ans = 1e8 + 5;
  for (int i = 1; i <= (n); i++) {
    ans = min(ans, back(1, n, i, 1));
  }
  if (ans == 1e8 + 5) ans = -1;
  printf("%d", ans);
  return 0;
}
