#include #define int long long #define inf ((int)1e18) #define OTIZM cin.tie(0)->sync_with_stdio(0); #define N 200005 using namespace std; int par[N],depth[N],sparse[20][N]; int32_t main() { OTIZM depth[1]=1; int n,q; cin>>n>>q; for(int i=2 ; i<=n ; i++){ cin>>sparse[0][i]; depth[i]=depth[sparse[0][i]] + 1; } for(int i = 1 ; i < 20; i++){ for(int j = 1; j <= n ; j++){ sparse[i][j] = sparse[i-1][sparse[i-1][j]]; } } while(q--){ int a,b; cin>>a>>b; if(depth[a]=0 ;i--){ if(sparse[i][a]!=sparse[i][b]){ a=sparse[i][a]; b=sparse[i][b]; } } cout<