#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;

int pr[100005];
int deep[100005];
pair <int, int> p[100005];
set <int> s;
set <int> r;
set <pair <int, int> > S;

int main()
{
	ios::sync_with_stdio(false);
	freopen("twopaths.in", "r", stdin);
	freopen("twopaths.out", "w", stdout);
	int n, k;
	cin >> n >> k;
	/*
	if (n > 100 && k > 100)
	{
		for (int i = 1; i < n; i++)
		{
			int x;
			cin >> x;
			pr[i] = x - 1;
		}	

		for (int i = 0; i < k; i++)
		{
			cin >> p[i].first >> p[i].second;
			if (S.find(p[i]) != S.end())
			{
				cout << "1" << endl;
				cout << p[i].first << " " << p[i].second << endl;
				return 0;
			}

			int t = p[i].first;
			p[i].first = p[i].second;
			p[i].second = t;
			if (S.find(p[i]) != S.end())
			{
				cout << "1" << endl;
				cout << p[i].first << " " << p[i].second << endl;
				return 0;
			}
			S.insert(p[i]);
		}
		cout << "0" << endl;
		cout << "1 2" << endl;
		return 0;  
	}
	*/

	//deep[0] = 1;
	for (int i = 1; i < n; i++)
	{
		int x;
		cin >> x;
		pr[i] = x - 1;
		//deep[i] = deep[x - 1] + 1;
	}

	for (int i = 0; i < k; i++)
	{
		cin >> p[i].first >> p[i].second;
		p[i].first--;
		p[i].second--;
	}

	int maxcnt = 0;
	int ii = 0, jj = 1;

	for (int i = 0; i < k; i++)
		for (int j = i + 1; j < k; j++)
		{
			//cout << i << " " << j << endl;
			int a = p[i].first;
			int b = p[i].second;		
			int c = p[j].first;
			int d = p[j].second;
			int ab = 0, cd = 0;

			s.insert(a);
			while (a != 0)    
			{
				s.insert(pr[a]);
				a = pr[a];
			}    
			if (s.find(b) != s.end())
				ab = b;
			else
				while (b != 0)    
				{
					if (s.find(pr[b]) != s.end())
					{
						ab = pr[b];
						break;
					}
					b = pr[b];
				}
		 	s.clear();
		 	s.insert(ab);
		 	a = p[i].first;
			b = p[i].second;		
		 	while (a != ab)    
			{
				s.insert(a);
				a = pr[a];
			}
			while (b != ab)    
			{
				s.insert(b);
				b = pr[b];
			}

			r.insert(c);
			while (c != 0)    
			{
				r.insert(pr[c]);
				c = pr[c];
			}
			if (r.find(d) != r.end())
				cd = d;
			else
				while (d != 0)    
				{
					if (r.find(pr[d]) != r.end())
					{
						cd = pr[d];
						break;
					}
					d = pr[d];
				}
			r.clear();

			//cout << i << " " << j << "    " << ab << " " << cd << endl;
			int cnt = 0;
			c = p[j].first;
			d = p[j].second;
			while (c != cd)    
			{         
				if (s.find(c) != s.end() && s.find(pr[c]) != s.end())
					cnt++;
				c = pr[c];
			}
			while (d != cd)    
			{
				if (s.find(d) != s.end() && s.find(pr[d]) != s.end())
					cnt++;
				d = pr[d];
			}
			s.clear();

      if (maxcnt < cnt)
      {
      	maxcnt = cnt;
      	ii = i;
      	jj = j;
      }
      //cout << cnt << endl;	 	
		}

	cout << maxcnt << endl;
	cout << ii + 1 << " " << jj + 1 << endl;

	return 0;
}