#include<cstdio>
#include<cstdlib>
#include<cstdint>
#include<cstddef>
#include<algorithm>
#include<vector>
#include"finale.h"

namespace grader{
    const std::int32_t N = 0x30d45, LOG = 0x13, MAXQ = 0x30d40;
    std::int32_t c, t, n, x, cq, mq, f[LOG][N], lg[N], dfn[N], out[N], tim, fa[LOG][N], dep[N], dsu[N];
    std::vector<std::int32_t> G[N];

    __attribute__((noreturn)) inline void quit_wa(const char* m){ std::printf("Wrong answer: %s\n", m), std::exit(~0 ^ ~0); }
    __attribute__((noreturn)) inline void quit_invalid(const char* m){ std::printf("Invalid operation: %s\n", m), std::exit(~0 ^ ~0); }
    inline auto find_set(std::int32_t u) noexcept -> std::int32_t { return u[dsu] == u ? u : (u[dsu] = find_set(u[dsu])); }
    inline auto getmin(std::int32_t a, std::int32_t b) noexcept -> std::int32_t { return (!a || !b) ? (a | b) : (a[dfn] < b[dfn] ? a : b); }

    void dfs(std::int32_t u, std::int32_t p, std::int32_t d) noexcept {
        u[dep] = d, u[0[fa]] = p, (u[dfn] = ++ tim)[0[f]] = p;
        for(std::int32_t i = 1;i < LOG;i ++) u[i[fa]] = u[(i - 1)[fa]] ? u[(i - 1)[fa]][(i - 1)[fa]] : 0;
        for(const std::int32_t& v : u[G]) (v ^ p) && (dfs(v, u, d + 1), 0);
        u[out] = tim;
    }

    void build(std::int32_t m) noexcept {
        for(std::int32_t i = 1;i < LOG;i ++) for(std::int32_t j = 1;j + (1 << i) - 1 <= m;j ++) j[i[f]] = getmin(j[(i - 1)[f]], (j + (1 << (i - 1)))[(i - 1)[f]]);
    }

    inline auto lca(std::int32_t u, std::int32_t v) noexcept -> std::int32_t {
        if(__builtin_expect((static_cast<std::uint32_t>(u - 1) >= static_cast<std::uint32_t>(n)) | (static_cast<std::uint32_t>(v - 1) >= static_cast<std::uint32_t>(n)), 0)) quit_invalid("vertex out of range");
        if(u == v) return u;
        if(u[dfn] > v[dfn]) u ^= v ^= u ^= v;
        const std::int32_t d = (v[dfn] - u[dfn])[lg];
        return getmin((u[dfn] + 1)[d[f]], (v[dfn] - (1 << d) + 1)[d[f]]);
    }

    inline auto ancestor(std::int32_t u, std::int32_t p) noexcept -> bool {
        return !((static_cast<std::uint32_t>(u - 1) >= static_cast<std::uint32_t>(n)) | (static_cast<std::uint32_t>(p - 1) >= static_cast<std::uint32_t>(n))) && (u ^ p) && (u[dfn] < p[dfn]) && (p[out] <= u[out]);
    }

    inline auto getkt(std::int32_t u, std::int32_t k) noexcept -> std::int32_t {
        if(__builtin_expect(static_cast<std::uint32_t>(k) > static_cast<std::uint32_t>(u[dep]), 0)) quit_invalid("k out of bounds");
        for(std::int32_t i = 0;(static_cast<std::uint32_t>(k) >> i) && i < LOG;i ++) if((static_cast<std::uint32_t>(k) >> i) & 1U) if(!(u = u[i[fa]]) && ((static_cast<std::uint32_t>(k) >> (i + 1)) != 0U)) quit_invalid("jumped over root");
        return u;
    }

    inline void clear(std::int32_t m) noexcept {
        tim = cq = 0[dfn] = 0[out] = 0, 0[dep] = ~0;
        for(std::int32_t i = 0;i < LOG;i ++) 0[i[fa]] = 0;
        for(std::int32_t i = 1;i <= m;i ++){
            std::vector<std::int32_t>().swap(i[G]), i[dfn] = i[out] = i[dep] = 0, i[dsu] = i;
            for(std::int32_t j = 0;j < LOG;j ++) i[j[fa]] = i[j[f]] = 0;
        }
    }
}

int query_d(int u_in){
    using namespace grader; const std::int32_t u = static_cast<std::int32_t>(u_in);
    if(__builtin_expect(static_cast<std::uint32_t>(u - 1) >= static_cast<std::uint32_t>(n) || ++ cq > MAXQ, 0)) quit_invalid("invalid query_d");
    return static_cast<int>(u[dep] + x[dep] - (lca(u, x)[dep] << 1));
}

int query_s(int u_in){
    using namespace grader; const std::int32_t u = static_cast<std::int32_t>(u_in);
    if(__builtin_expect(static_cast<std::uint32_t>(u - 1) >= static_cast<std::uint32_t>(n) || ++ cq > MAXQ || !ancestor(u, x), 0)) quit_invalid("invalid query_s");
    return static_cast<int>(getkt(x, x[dep] - u[dep] - 1));
}

int main(){
    using namespace grader;
    for(std::int32_t i = (1[lg] = 0, 2);i < N;i ++) i[lg] = (i >> 1)[lg] + 1;
    if(__builtin_expect((std::scanf("%d%d", &c, &t) ^ 2) || t <= 0, 0)) quit_invalid("invalid c/t");
    init(static_cast<int>(c), static_cast<int>(t));
    for(std::int32_t ct = 1;ct <= t;++ ct){
        if(__builtin_expect((std::scanf("%d%d", &n, &x) ^ 2) || (static_cast<std::uint32_t>(n - 1) >= static_cast<std::uint32_t>(N - 1)) || (static_cast<std::uint32_t>(x - 1) >= static_cast<std::uint32_t>(n)), 0)) quit_invalid("invalid n/x");
        clear(n); std::vector<int> eu(static_cast<std::size_t>(n - 1)), ev(static_cast<std::size_t>(n - 1)); std::int32_t cc = n;
        for(std::int32_t i = 0;i < n - 1;i ++){
            if(__builtin_expect((std::scanf("%d%d", eu.data() + i, ev.data() + i) ^ 2) != 0, 0)) quit_invalid("read edge error");
            const std::int32_t u = static_cast<std::int32_t>(*(eu.data() + i)), v = static_cast<std::int32_t>(*(ev.data() + i));
            if(__builtin_expect((static_cast<std::uint32_t>(u - 1) >= static_cast<std::uint32_t>(n)) | (static_cast<std::uint32_t>(v - 1) >= static_cast<std::uint32_t>(n)) | (u == v), 0)) quit_invalid("endpoint error");
            const std::int32_t fu = find_set(u), fv = find_set(v);
            if(__builtin_expect(fu == fv, 0)) quit_invalid("cycle detected");
            fu[dsu] = fv, -- cc, u[G].push_back(v), v[G].push_back(u);
        }
        if(__builtin_expect((cc ^ 1) || (dfs(1, 0, 0), tim ^ n), 0)) quit_invalid("graph is not a tree");
        build(n); const int ans = find_node(static_cast<int>(n), eu, ev);
        if(__builtin_expect((static_cast<std::uint32_t>(ans - 1) >= static_cast<std::uint32_t>(n)) || (static_cast<std::int32_t>(ans) ^ x), 0)) quit_wa("bad result");
        mq = std::max(mq, cq);
    }
    return std::printf("Correct.\n%d\n", mq), 0;
}
