#include <iostream>
#include <fstream>
using namespace std;

//ifstream f("wow.in");

#define LE 100666
#include <vector>
#define pb push_back
#define f cin

int fap[LE],lap[LE],up[20][LE];
bool viz[LE];
int lev[LE],K,lmax;

vector<int> H[LE];

void dfs(int nod)
{
    int N=H[nod].size(),i;
    viz[nod]=true;
    fap[nod]=++K;


    for(i=0; i<N; ++i)
    {
        int D=H[nod][i];

        if (viz[D]==false)
        {
            lev[D]=lev[nod]+1;
            up[0][D]=nod;
            dfs(D);
        }
    }

    lap[nod]=++K;
}

bool inside(int RAD,int nod_check)
{
    if (fap[nod_check]>=fap[RAD]&&fap[nod_check]<=lap[RAD]) return true;
    return false;
}

int lca(int nod1,int nod2)
{
    if (lev[nod1]<lev[nod2]) swap(nod1,nod2);
    int D=lev[nod1]-lev[nod2],i;

    for(i=0; i<=lmax; ++i)
        if (D&(1<<i))
            nod1=up[i][nod1];


    if (nod1==nod2) return nod1;

    for(i=lmax; i>=0; --i)
        if (up[i][nod1]!=up[i][nod2])
            nod1=up[i][nod1],nod2=up[i][nod2];

    int res=up[0][nod1];
    return res;
}

int main()
{
    int n,m,i,l;

    f>>n>>m;

    for(i=1; i<n; ++i)
    {
        int xx,yy;
        f>>xx>>yy;
        H[xx].pb(yy);
        H[yy].pb(xx);
    }

    dfs(1);

    up[1][0]=1;

    for(l=1; (1<<l)<=n; ++l)
        for(i=1; i<=n; ++i)
            up[l][i]=up[l-1][up[l-1][i]];

    lmax=l-1;

    int CEO=1;

    for(i=1; i<=m; ++i)
    {
        int typ,xx,yy;
        f>>typ;

        if (typ==1)
        {
            f>>CEO;
            continue;
        }

        if (typ==2)
        {
            f>>xx>>yy;
            int LC=lca(xx,yy);

            if (xx==CEO||yy==CEO)
            {
              cout<<-1;
              continue;
            }

            if (inside(LC,CEO)==false)
            {
                if (LC==xx||LC==yy)
                {
                  cout<<-1<<'\n';
                  continue;
                }

                cout<<LC<<'\n';
                continue;
            }

            if(inside(xx,CEO)||inside(yy,CEO))
            {
                if (LC==xx||LC==yy)
                {
                  if (lca(xx,CEO)==CEO||lca(yy,CEO)==CEO)
                  {
                  cout<<CEO<<'\n';
                  continue;
                  }
                }

                cout<<-1<<'\n';
                continue;
            }

            int lc1=lca(xx,CEO);
            int lc2=lca(yy,CEO);


            if (lev[lc1]<lev[lc2]) swap(lc1,lc2);
            cout<<lc1<<'\n';
            continue;
        }
    }


    return 0;
}