#include using namespace std; typedef long long ll; typedef pair P; #define DUMP(x) cout << #x << " = " << (x) << endl; #define FOR(i, m, n) for (ll i = m; i < n; i++) #define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--) #define REP(i, n) FOR(i, 0, n) #define IREP(i, n) IFOR(i, 0, n) #define FOREACH(x, a) for (auto&(x) : (a)) #define ALL(v) (v).begin(), (v).end() #define SZ(x) ll(x.size()) ll n, k; vector> to; vector dist; void dfs(ll cv, ll par, ll d) { dist[cv] = d; FOREACH(nv, to[cv]) { if (nv == par) { continue; } dfs(nv, cv, d + 1); } } int main() { cin >> n >> k; to = vector>(n); REP(i, n - 1) { ll a, b; cin >> a >> b; a--, b--; to[a].push_back(b); to[b].push_back(a); } dist = vector(n); dfs(0, -1, 0); sort(ALL(dist)); if (n < k) { cout << -1 << endl; exit(0); } ll ans = 0; REP(i, k) { ans += dist[i]; } cout << ans << endl; }