#include using namespace std; using ll = long long; using Graph = vector>; void dfs(const Graph &g, vector &visit, int v) { if (visit[v]) return; visit[v] = true; for (auto e : g[v]) { dfs(g, visit, e); } } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, k; cin >> n >> k; Graph g(n); for (int i = 0; i < n - 1; i++) { int a, b; cin >> a >> b; a--; b--; g[a].push_back(b); g[b].push_back(a); } if (k >= n) { cout << -1 << endl; return 0; } vector visit(n, false); dfs(g, visit, 0); for (int i = 0; i < n; i++) { if (!visit[i]) { cout << -1 << endl; return 0; } } cout << (k - 1) << endl; return 0; }