#include <bits/stdc++.h>
using namespace std;
const int N = 80, inf = (1 << 30) - 1;
int k, f[N][N][N][N];
bool vis[N][N][N][N];
struct Edge {
  int v, w;
};
vector<Edge> adj[N];
int dp(int x, int y, int z, int w) {
  int& now = f[x][y][z][w];
  bool& visited = vis[x][y][z][w];
  if (visited) return now;
  visited = true;
  if (w == k - 1) return now = 0;
  now = inf;
  if (x > y) return now;
  for (int i = (0), i_end = (adj[z].size()); i < i_end; ++i) {
    int t = adj[z][i].v;
    if (t >= x && t <= y) {
      if (t < z)
        now = min(now, dp(x, z - 1, t, w + 1) + adj[z][i].w);
      else
        now = min(now, dp(z + 1, y, t, w + 1) + adj[z][i].w);
    }
  }
  return now;
}
int main() {
  int n, m;
  scanf("%d%d%d", &n, &k, &m);
  for (int i = (0), i_end = (m); i < i_end; ++i) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    --u;
    --v;
    if (u != v) adj[u].push_back((Edge){v, w});
  }
  int ans = inf;
  for (int i = (0), i_end = (n); i < i_end; ++i)
    ans = min(ans, dp(0, n - 1, i, 0));
  printf("%d\n", ans == inf ? -1 : ans);
  return 0;
}
