#include <bits/stdc++.h>
using Int = long long;  // clang-format off
using pii = std::pair<Int, Int>;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define RREP_(i, a_, b_, a, b, ...) for (Int i = Int(b) - 1, low##i = (a); i >= low##i; i--)
#define RREP(i, ...) RREP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define ALL(v) std::begin(v), std::end(v)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on
struct in {
    template <class T> operator T() {
        T t;
        std::cin >> t;
        return t;
    }
};
void out() { std::cout << "\n"; }
template <class Head, class... Tail> void out(Head&& h, Tail&&... t) {
    std::cout << h << (sizeof...(Tail) == 0 ? "" : " "), out(std::forward<Tail>(t)...);
}
template <class T> bool chmin(T& a, const T& b) { return a > b ? a = b, true : false; }
template <class T> bool chmax(T& a, const T& b) { return a < b ? a = b, true : false; }
template <class T> using V = std::vector<T>;

/**
 *    author:  knshnb
 *    created: Tue Mar 30 22:53:03 JST 2021
 **/

/// @docs src/Helper/BinarySearch.md
template <class F> long long binary_search(long long ok, long long ng, F check) {
    while (std::abs(ok - ng) > 1) {
        long long mid = (ok + ng) / 2;
        (check(mid) ? ok : ng) = mid;
    }
    return ok;
}

signed main() {
    Int n = in(), K = in();
    V<V<Int>> g(n);
    REP(i, n - 1) {
        Int u = (Int)in() - 1, v = (Int)in() - 1;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    auto check = [&](Int mid) {
        Int cnt = 0;
        V<Int> no_ma(n, 0), mi(n, 1e18);
        auto dfs = [&](auto&& self, int v, int prv = -1) -> void {
            for (int s : g[v]) {
                if (s == prv) continue;
                self(self, s, v);
                chmin(mi[v], mi[s] + 1);
                chmax(no_ma[v], no_ma[s] + 1);
            }
            if (no_ma[v] + mi[v] <= mid) no_ma[v] = -1;
            if (no_ma[v] >= mid) {
                cnt++;
                no_ma[v] = -1;
                mi[v] = 0;
            }
        };
        dfs(dfs, 0);
        if (no_ma[0] >= 0) cnt++;
        return cnt <= K;
    };
    Int ans = binary_search(n, -1, check);
    out(ans);
}

#include <bits/stdc++.h>

#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define FILL0(x) memset(x,0,sizeof(x))
#define FILL1(x) memset(x,-1,sizeof(x))

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int a, b;
    cin >> a >> b;
    a += b;

    if(a>=15 && b>=8){
        cout << 1 << endl;
    }else if(a>=10 && b>=3){
        cout << 2 << endl;
    }else if(a>=3){
        cout << 3 << endl;
    }else{
        cout << 4 << endl;
    }



    return 0;

}
