import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.Queue;
import java.util.Random;
import java.util.Set;
import java.util.SortedSet;
import java.util.Stack;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main
{
	/********************************************** a list of common variables **********************************************/
	private MyScanner scan = new MyScanner();
	private PrintWriter out = new PrintWriter(System.out);
	private final double PI = Math.acos(-1.0);
	private final int SIZEN = (int)(1e5);
	private final int MOD = (int)(1e9 + 7);
	private final int[] DX = {0, 1, 0, -1}, DY = {-1, 0, 1, 0};
	private ArrayList<Integer>[] edge;

	public void foo()
	{
		int n = scan.nextInt();
		int m = scan.nextInt();
		char[][] score = new char[n][];
		int[] maxScore = new int[m];
		for(int i = 0;i < n;++i)
		{
			score[i] = scan.next().toCharArray();
			for(int j = 0;j < m;++j)
			{
				maxScore[j] = Math.max(maxScore[j], score[i][j]);
			}
		}
		int ans = 0;
		for(int i = 0;i < n;++i)
		{
			for(int j = 0;j < m;++j)
			{
				if(score[i][j] == maxScore[j])
				{
					++ans;
					break;
				}
			}
		}
		out.println(ans);
	}

	public static void main(String[] args)
	{
		Main m = new Main();
		m.foo();
		m.out.close();
	}

	/********************************************** a list of common algorithms **********************************************/
	/**
	 * 1---Get greatest common divisor
	 * @param a :	first number
	 * @param b :	second number
	 * @return		greatest common divisor
	 */
	public long gcd(long a, long b)
	{
		return 0 == b ? a : gcd(b, a % b);
	}

	/**
	 * 2---Get the distance from a point to a line
	 * @param x1	the x coordinate of one endpoint of the line
	 * @param y1	the y coordinate of one endpoint of the line
	 * @param x2	the x coordinate of the other endpoint of the line
	 * @param y2	the y coordinate of the other endpoint of the line
	 * @param x		the x coordinate of the point
	 * @param y		the x coordinate of the point
	 * @return		the distance from a point to a line
	 */
	public double getDist(long x1, long y1, long x2, long y2, long x, long y)
	{
		long a = y2 - y1;
		long b = x1 - x2;
		long c = y1 * (x2 - x1) - x1 * (y2 - y1);
		return Math.abs(a * x + b * y + c) / Math.sqrt(a * a + b * b);
	}

	/**
	 * 3---Get the distance from one point to a segment (not a line)
	 * @param x1	the x coordinate of one endpoint of the segment
	 * @param y1	the y coordinate of one endpoint of the segment
	 * @param x2	the x coordinate of the other endpoint of the segment
	 * @param y2	the y coordinate of the other endpoint of the segment
	 * @param x		the x coordinate of the point
	 * @param y		the y coordinate of the point
	 * @return		the distance from one point to a segment (not a line)
	 */
	public double ptToSeg(long x1, long y1, long x2, long y2, long x, long y)
	{
		double cross = (x2 - x1) * (x - x1) + (y2 - y1) * (y - y1);
		if(cross <= 0)
		{
			return (x - x1) * (x - x1) + (y - y1) * (y - y1);
		}
		double d = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
		if(cross >= d)
		{
			return (x - x2) * (x - x2) + (y - y2) * (y - y2);
		}
		double r = cross / d;
		double px = x1 + (x2 - x1) * r;
		double py = y1 + (y2 - y1) * r;
		return (x - px) * (x - px) + (y - py) * (y - py);
	}

	/**
	 * 4---KMP match, i.e. kmpMatch("abcd", "bcd") = 1, kmpMatch("abcd", "bfcd") = -1.
	 * @param t:	String to match.
	 * @param p:	String to be matched.
	 * @return		if can match, first index; otherwise -1.
	 */
	public int kmpMatch(char[] t, char[] p)
	{
		int n = t.length;
		int m = p.length;
		int[] next = new int[m + 1];
		next[0] = -1;
		int j = -1;
		for(int i = 1;i < m;++i)
		{
			while(j >= 0 && p[i] != p[j + 1])
			{
				j = next[j];
			}
			if(p[i] == p[j + 1])
			{
				++j;
			}
			next[i] = j;
		}
		j = -1;
		for(int i = 0;i < n;++i)
		{
			while(j >= 0 && t[i] != p[j + 1])
			{
				j = next[j];
			}
			if(t[i] == p[j + 1])
			{
				++j;
			}
			if(j == m - 1)
			{
				return i - m + 1;
			}
		}
		return -1;
	}

	class MyScanner
	{
	    private byte[] buf = new byte[1024];
	    private int curChar;
	    private int numChars;
	    BufferedInputStream bis = new BufferedInputStream(System.in);

	    public int read()
	    {
	        if (-1 == numChars)
	        {
	        	throw new InputMismatchException();
	        }
	        if (curChar >= numChars)
	        {
	            curChar = 0;
	            try
	            {
	                numChars = bis.read(buf);
	            }
	            catch (IOException e)
	            {
	                throw new InputMismatchException();
	            }
	            if (numChars <= 0)
	            {
	            	return -1;
	            }
	        }
	        return buf[curChar++];
	    }

	    public int nextInt()
	    {
	        int c = read();
	        while (isSpaceChar(c))
	        {
	        	c = read();
	        }
	        int sgn = 1;
	        if (c == '-')
	        {
	            sgn = -1;
	            c = read();
	        }
	        int res = 0;
	        do
	        {
	            if (c < '0' || c > '9')
	            {
	            	throw new InputMismatchException();
	            }
	            res *= 10;
	            res += c - '0';
	            c = read();
	        } while (!isSpaceChar(c));
	        return res * sgn;
	    }

	    public long nextLong()
	    {
	    	int c = read();
	    	while (isSpaceChar(c))
	    	{
	    		c = read();
	    	}
	    	int sgn = 1;
	    	if (c == '-')
	    	{
	    		sgn = -1;
	    		c = read();
	    	}
	    	long res = 0;
	    	do
	    	{
	    		if (c < '0' || c > '9')
	    		{
	    			throw new InputMismatchException();
	    		}
	    		res *= 10;
	    		res += c - '0';
	    		c = read();
	    	} while (!isSpaceChar(c));
	    	return res * sgn;
	    }

	    public double nextDouble()
	    {
	        int c = read();
	        while (isSpaceChar(c))
	        {
	        	c = read();
	        }
	        int sgn = 1;
	        if (c == '-')
	        {
	            sgn = -1;
	            c = read();
	        }
	        double res = 0;
	        while (!isSpaceChar(c) && c != '.')
	        {
	            if (c == 'e' || c == 'E')
	            {
	            	return res * Math.pow(10, nextInt());
	            }
	            if (c < '0' || c > '9')
	            {
	            	throw new InputMismatchException();
	            }
	            res *= 10;
	            res += c & 15;
	            c = read();
	        }
	        if (c == '.')
	        {
	            c = read();
	            double m = 1;
	            while (!isSpaceChar(c))
	            {
	                if (c == 'e' || c == 'E')
	                {
	                	return res * Math.pow(10, nextInt());
	                }
	                if (c < '0' || c > '9')
	                {
	                	throw new InputMismatchException();
	                }
	                m /= 10;
	                res += (c & 15) * m;
	                c = read();
	            }
	        }
	        return res * sgn;
	    }

	    public String next()
	    {
	        int c = read();
	        while (isSpaceChar(c))
	        {
	        	c = read();
	        }
	        StringBuilder res = new StringBuilder();
	        do
	        {
	            res.appendCodePoint(c);
	            c = read();
	        } while (!isSpaceChar(c));
	        return res.toString();
	    }

	    private boolean isSpaceChar(int c)
	    {
	        return ' ' == c || '\n' == c || '\r' == c || '\t' == c || -1 == c;
	    }
	}
}


#include<bits/stdc++.h>
using namespace std;
int inp[105],temp[10005],temp1[105],numstudent,numsubject,c,f;
	char Inp[101][101];
int main()
{

  	scanf("%d%d",&numstudent,&numsubject);
  	for(int i=0;i<numstudent;++i)
      cin>>Inp[i];

  	for(int i=0;i<numsubject;++i)
  		{for(int j=0;j<numstudent;++j)
  			inp[j]=temp1[j]=(Inp[j][i]-'0');

  	sort(inp,inp+numstudent);
  	for(int j=0;j<numstudent;++j)
  	          if(temp1[j]==inp[numstudent-1])
    	       temp[f++]=j+1;
  		}
  	sort(temp,temp+f);

  	for(int j=0;j<f;++j)
  		if(temp[j]!=temp[j+1])
  		c++;
  	cout<<c<<endl;
return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	char s[150][150];
int base[250],c=0,max,total=0,n,m;
cin>>n>>m;
for(int i=1;i<=n;++i)
for(int j=1;j<=n;j++)
	cin>>s[i][j];
max=s[1][1]-'0';
base[c]=1;
for(int i=1;i<=m;++i)
{for(int j=2;j<=n;++j)
	if(max<(s[j][i]-'0'))
    {max=s[j][i]-'0';
      base[c++]=j;
     }
   for(int k=1;k<=n;++k)
	   if(s[k][i]-'0'==max)
		   base[c++]=k;
   max=s[1][i+1]-'0';

}
sort(base,base+c);
unique(base,base+c);
for(int i=0;i<c;++i)
	if(base[i]==*max_element(base,base+c))
		{total++;
		break;}
	else
		total++;

cout<<total<<endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int inp[205],temp[205],temp1[205],numstudent,numsubject,c,f;
	char Inp[102][102];
int main()
{

  	scanf("%d%d",&numstudent,&numsubject);
  	for(int i=0;i<numstudent;++i)
      cin>>Inp[i];

  	for(int i=0;i<numsubject;++i)
  		{for(int j=0;j<numstudent;++j)
  			inp[j]=temp1[j]=(Inp[j][i]-'0');

  	sort(inp,inp+numstudent);
  	for(int j=0;j<numstudent;++j)
  	          if(temp1[j]==inp[numstudent-1])
    	       temp[f++]=j+1;
  		}
  	sort(temp,temp+f);

  	for(int j=0;j<f;++j)
  		if(temp[j]!=temp[j+1])
  		c++;
  	cout<<c<<endl;
return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	char s[150][150];
int base[250],c=0,max,total=0,n,m,b;
cin>>n>>m;
for(int i=1;i<=n;++i)
for(int j=1;j<=m;j++)
	cin>>s[i][j];
max=s[1][1]-'0';
b=1;
for(int i=1;i<=m;++i)
{for(int j=2;j<=n;++j)
	if(max<(s[j][i]-'0'))
    {max=s[j][i]-'0';
      b=j;
     }
base[c++]=b;
   for(int k=1;k<=n;++k)
	   if(s[k][i]-'0'==max)
		   base[c++]=k;
   max=s[1][i+1]-'0';

}
sort(base,base+c);
unique(base,base+c);
for(int i=0;i<c;++i)
	if(base[i]==*max_element(base,base+c))
		{total++;
		break;}
	else
		total++;

cout<<total<<endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	char s[150][150];
int base[250],c=0,max,total=0,n,m;
cin>>n>>m;
for(int i=1;i<=n;++i)
for(int j=1;j<=n;j++)
	cin>>s[i][j];
max=s[1][1]-'0';
base[c]=1;
for(int i=1;i<=m;++i)
{for(int j=2;j<=n;++j)

	if(max<(s[j][i]-'0'))
    {max=s[j][i]-'0';
      base[c++]=j;
     }
   for(int k=1;k<=n;++k)
	   if(s[k][i]-'0'==max)
		   base[c++]=k;
   max=s[1][i+1]-'0';

}
sort(base,base+c);
for(int i=0;i<c;++i)
	if(base[i]==*max_element(base,base+c))
		{total++;
		break;}
	else
		total++;

cout<<total<<endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int inp[101],temp[101],temp1[101],numstudent,numsubject,c,f;
	char Inp[100][100];
int main()
{

  	scanf("%d%d",&numstudent,&numsubject);
  	for(int i=0;i<numstudent;++i)
      cin>>Inp[i];

  	for(int i=0;i<numsubject;++i)
  		{for(int j=0;j<numstudent;++j)
  			inp[j]=temp1[j]=(Inp[j][i]-'0');

  	sort(inp,inp+numstudent);
  	for(int j=0;j<numstudent;++j)
  	          if(temp1[j]==inp[numstudent-1])
    	       temp[f++]=j+1;
  		}
  	sort(temp,temp+f);

  	for(int j=0;j<f;++j)
  		if(temp[j]!=temp[j+1])
  		c++;
  	cout<<c<<endl;
return 0;
}


#include<bits/stdc++.h>
using namespace std;
int inp[102],temp[102],temp1[102],numstudent,numsubject,c,f;
	char Inp[102][102];
int main()
{

  	scanf("%d%d",&numstudent,&numsubject);
  	for(int i=0;i<numstudent;++i)
      cin>>Inp[i];

  	for(int i=0;i<numsubject;++i)
  		{for(int j=0;j<numstudent;++j)
  			inp[j]=temp1[j]=(Inp[j][i]-'0');

  	sort(inp,inp+numstudent);
  	for(int j=0;j<numstudent;++j)
  	          if(temp1[j]==inp[numstudent-1])
    	       temp[f++]=j+1;
  		}
  	sort(temp,temp+f);

  	for(int j=0;j<f;++j)
  		if(temp[j]!=temp[j+1])
  		c++;
  	cout<<c<<endl;
return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	char s[150][150];
int base[250],c=0,max,total=0,n,m;
cin>>n>>m;
for(int i=1;i<=n;++i)
for(int j=1;j<=m;j++)
	cin>>s[i][j];
max=s[1][1]-'0';
base[c]=1;
for(int i=1;i<=m;++i)
{for(int j=2;j<=n;++j)
	if(max<(s[j][i]-'0'))
    {max=s[j][i]-'0';
      base[c++]=j;
     }
   for(int k=1;k<=n;++k)
	   if(s[k][i]-'0'==max)
		   base[c++]=k;
   max=s[1][i+1]-'0';

}
sort(base,base+c);
unique(base,base+c);
for(int i=0;i<c;++i)
	if(base[i]==*max_element(base,base+c))
		{total++;
		break;}
	else
		total++;

cout<<total<<endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,count=0;
    cin>>n>>m;

    char x, max1[m]={""},xx[n][m];
    bool x2[n];
    for(int c=0;c<n;c++)
    {
        for(int i=0;i<m;i++)
        {
            cin>>xx[c][i];
            x2[c]=true;
            if(max1[i]<=xx[c][i])
            max1[i]=xx[c][i];
        }
    }

    for(int c=0;c<m;c++)
    {

        for(int i=0;i<n;i++)
        {
            if(max1[c]==xx[i][c]&&x2[i])
                {count++;x2[i]=false;}
        }
    }
    cout<<count<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,count=0;
    cin>>n>>m;
    vector<char>max1(m,'0');
    char x, xx[n][m];
    bool x2[n];

    for(int c=0;c<n;c++)
    {
        for(int i=0;i<m;i++)
        {
            cin>>xx[c][i];
            x2[c]=true;
            if(max1[i]<=xx[c][i])
            max1[i]=xx[c][i];
        }
    }

    for(int c=0;c<m;c++)
    {

        for(int i=0;i<n;i++)
        {
            if(max1[c]==xx[i][c]&&x2[i])
                {count++;x2[i]=false;}
        }
    }
    cout<<count<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,count=0;
    cin>>n>>m;

    char x, max1[m];
    while(n--)
    {

        bool temp=true;
        for(int i=0;i<m;i++)
        {
            cin>>x;
            if(max1[i]<=x)
            {max1[i]=x;if(temp){count++;temp=0;}}

        }
    }
    cout<<count<<endl;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,count=0;
    cin>>n>>m;

    char x, max1[m],xx[n][m];
    bool x2[n];
    for(int i=0;i<m;i++)
        max1[i]='0';
    for(int c=0;c<n;c++)
    {
        for(int i=0;i<m;i++)
        {
            cin>>xx[c][i];
            x2[c]=true;
            if(max1[i]<=xx[c][i])
            max1[i]=xx[c][i];
        }
    }

    for(int c=0;c<m;c++)
    {

        for(int i=0;i<n;i++)
        {
            if(max1[c]==xx[i][c]&&x2[i])
                {count++;x2[i]=false;}
        }
    }
    cout<<count<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,count=0;
    cin>>n>>m;
    vector<char>max1('0',m);
    char x, xx[n][m];
    bool x2[n];

    for(int c=0;c<n;c++)
    {
        for(int i=0;i<m;i++)
        {
            cin>>xx[c][i];
            x2[c]=true;
            if(max1[i]<=xx[c][i])
            max1[i]=xx[c][i];
        }
    }

    for(int c=0;c<m;c++)
    {

        for(int i=0;i<n;i++)
        {
            if(max1[c]==xx[i][c]&&x2[i])
                {count++;x2[i]=false;}
        }
    }
    cout<<count<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,count=0;
    cin>>n>>m;
    vector<char>max1(m,'0');
    char x, xx[n][m];
    bool x2[n];
    cout<<max1.size()<<endl;
    for(int c=0;c<n;c++)
    {
        for(int i=0;i<m;i++)
        {
            cin>>xx[c][i];
            x2[c]=true;
            if(max1[i]<=xx[c][i])
            max1[i]=xx[c][i];
        }
    }

    for(int c=0;c<m;c++)
    {

        for(int i=0;i<n;i++)
        {
            if(max1[c]==xx[i][c]&&x2[i])
                {count++;x2[i]=false;}
        }
    }
    cout<<count<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,count=0;
    cin>>n>>m;
    vector<char>max1('0',m+5);
    char x, xx[n][m];
    bool x2[n];

    for(int c=0;c<n;c++)
    {
        for(int i=0;i<m;i++)
        {
            cin>>xx[c][i];
            x2[c]=true;
            if(max1[i]<=xx[c][i])
            max1[i]=xx[c][i];
        }
    }

    for(int c=0;c<m;c++)
    {

        for(int i=0;i<n;i++)
        {
            if(max1[c]==xx[i][c]&&x2[i])
                {count++;x2[i]=false;}
        }
    }
    cout<<count<<endl;
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <set>
using namespace std;
int n,m,i,j;
string s [100], mx;
set <int> se;
int main() {
	scanf ("%d %d",&n,&m);
	for (i=0;i<m;i++){
		mx[i]+='0';
	}
	for (i=0;i<n;i++){
		cin>>s[i];
		for (j=0;j<m;j++){
			if (s[i][j]>mx[j]){
				mx[j]=s[i][j];
			}
		}
	}
	for (i=0;i<n;i++){
		for(j=0;j<m;j++)
			if(s[i][j]==mx[j])
				se.insert(i+1);
	}
	cout<<se.size()<<endl;
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <set>
#include<functional>
using namespace std;
int n,m,i,j;
string s [100], mx;
set <int> se;
int main() {
	scanf ("%d %d",&n,&m);
	for (i=0;i<m;i++){
		mx+='0';
	}
	for (i=0;i<n;i++){
		cin>>s[i];
		for (j=0;j<m;j++){
			if (s[i][j]>mx[j]){
				mx[j]=s[i][j];
			}
		}
	}
	for (i=0;i<n;i++){
		for(j=0;j<m;j++)
			if(s[i][j]==mx[j])
				se.insert(i+1);
	}
	cout<<se.size()<<endl;
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <set>
using namespace std;
int n,m,i,j;
string s [100], mx;
set <int> se;
int main() {
	scanf ("%d %d",&n,&m);
	for (i=0;i<m;i++){
		mx[i]+='0';
	}
	for (i=0;i<n;i++){
		cin>>s[i];
		for (j=0;j<m;j++){
			if (s[i][j]>mx[j]){
				mx[j]=s[i][j];
			}
		}
	}
	for (i=0;i<n;i++){
		for(j=0;j<m;j++)
			if(s[i][j]==mx[j])se.insert(i+1);
	}
	printf("%d\n",se.size());
	return 0;
}


#include<functional>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <string>
#include <set>
#include <bitset>
using namespace std;
typedef long long ll;
int n, m;
string mx;
vector<string> s;
set <int> se;
int main() {
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++) {
		mx+='0';
	}
	s.resize(n);
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		for (int j = 0; j < m; j++) {
			if (s[i][j] > mx[j]) {
				mx[j] = s[i][j];
			}
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++)
			if (s[i][j] == mx[j])
				se.insert(i + 1);
	}
	printf("%d\n", se.size());
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <set
#include<functional>
using namespace std;
int n,m,i,j;
string s [100], mx;
set <int> se;
int main() {
	scanf ("%d %d",&n,&m);
	for (i=0;i<m;i++){
		mx[i]+='0';
	}
	for (i=0;i<n;i++){
		cin>>s[i];
		for (j=0;j<m;j++){
			if (s[i][j]>mx[j]){
				mx[j]=s[i][j];
			}
		}
	}
	for (i=0;i<n;i++){
		for(j=0;j<m;j++)
			if(s[i][j]==mx[j])
				se.insert(i+1);
	}
	cout<<se.size()<<endl;
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <set>
using namespace std;
int n,m,i,j;
string s [100], mx;
set <int> se;
int main() {
	scanf ("%d %d",&n,&m);
	for (i=0;i<m;i++){
		mx[i]+='0';
	}
	for (i=0;i<n;i++){
		cin>>s[i];
		for (j=0;j<m;j++){
			if (s[i][j]>mx[j]){
				mx[j]=s[i][j];
			}
		}
	}
	for (i=0;i<n;i++){
		for(j=0;j<m;j++)
			if(s[i][j]==mx[j])se.insert(i+1);
	}
	cout<<se.size()<<endl;
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <set>
using namespace std;
int n,m,i,j;
string s [100], mx;
set <int> se;
int main() {
	scanf ("%d %d",&n,&m);
	for (i=0;i<m;i++){
		mx[i]+="0";
	}
	for (i=0;i<n;i++){
		cin>>s[i];
		for (j=0;j<m;j++){
			if (s[i][j]>mx[j]){
				mx[j]=s[i][j];
			}
		}
	}
	for (i=0;i<n;i++){
		for(j=0;j<m;j++)
			if(s[i][j]==mx[j])se.insert(i+1);
	}
	printf("%d\n",se.size());
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <set>
#include <string>
using namespace std;
int n,m,i,j;
string s [100], mx;
set <int> se;
int main() {
	scanf ("%d %d",&n,&m);
	mx.resize(m)={0};
	for (i=0;i<n;i++){
		cin>>s[i];
		for (j=0;j<m;j++){
			if (s[i][j]>mx[j]){
				mx[j]=s[i][j];
			}
		}
	}
	for (i=0;i<n;i++){
		for(j=0;j<m;j++)
			if(s[i][j]==mx[j])
				se.insert(i+1);
	}
	cout<<se.size()<<endl;
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <set>
using namespace std;
int n,m,i,j;
string s [100], mx;
set <int> se;
int main() {
	scanf ("%d %d",&n,&m);
	for (i=0;i<m;i++){
		mx[i]='0';
	}
	for (i=0;i<n;i++){
		cin>>s[i];
		for (j=0;j<m;j++){
			if (s[i][j]>mx[j]){
				mx[j]=s[i][j];
			}
		}
	}
	for (i=0;i<n;i++){
		for(j=0;j<m;j++)
			if(s[i][j]==mx[j])se.insert(i+1);
	}
	printf("%d\n",se.size());
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <set>
#include<functional>
using namespace std;
int n,m,i,j;
string s [100], mx;
set <int> se;
int main() {
	scanf ("%d %d",&n,&m);
	for (i=0;i<m;i++){
		mx[i]+='0';
	}
	for (i=0;i<n;i++){
		cin>>s[i];
		for (j=0;j<m;j++){
			if (s[i][j]>mx[j]){
				mx[j]=s[i][j];
			}
		}
	}
	for (i=0;i<n;i++){
		for(j=0;j<m;j++)
			if(s[i][j]==mx[j])
				se.insert(i+1);
	}
	cout<<se.size()<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n,m,f[107];
char a[107][107];
int main()
{   //freopen("A.inp","r",stdin);
    //freopen("A.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin>>n>>m;
    memset(f,0,sizeof(f));
    int ans=0;
    for (int i=1;i<=n;++i)
    for (int j=1;j<=m;++j)
    cin>>a[i][j];
    for (int i=1;i<=m;++i)
    {   int k=0;
        for (int j=1;j<=n;++j)
        if (int(a[j][i])>k) k=int(a[j][i]);
        for (int j=1;j<=n;++j)
        if (int(a[j][i])==k) f[j]=1;
    }
    for (int i=1;i<=n;++i)
    if (f[i]==1) ans++;
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n,m,a[107][107];
string s;
int main()
{   //freopen("152A.inp","r",stdin);
    //freopen("152A.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin>>n>>m; int d=0;
    for (int i=1;i<=n;++i)
    {   cin>>s;
        for (int j=0;j<=m-1;++j) a[i][j+1]=int(s[j])-48;
    }
    for (int i=1;i<=m;++i)
    {   int nmax=0; int c=1;
        for (int j=1;j<=n;++j)
        if (a[j][i]>nmax)
        {   nmax=a[j][i]; c=1;    }
        else if (a[j][i]==nmax) c++;
        if (c==1) d++;
    }
    cout<<d;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n,m,a[107][107];
string s;
int main()
{   //freopen("152A.inp","r",stdin);
    //freopen("152A.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin>>n>>m; int d=0;
    for (int i=1;i<=n;++i)
    {   cin>>s;
        for (int j=0;j<=m-1;++j) a[i][j+1]=int(s[j])-48;
    }
    for (int i=1;i<=m;++i)
    {   int nmax=0; int c=1;
        for (int j=1;j<=m;++j)
        if (a[j][i]>nmax)
        {   nmax=a[j+1][i]; c=1;    }
        else if (a[j+1][i]==nmax) c++;
        if (c==1) d++;
    }
    cout<<d;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n,m,a[107][107];
string s;
int main()
{   //freopen("152A.inp","r",stdin);
    //freopen("152A.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin>>n>>m; int d=0;
    for (int i=1;i<=n;++i)
    {   cin>>s;
        for (int j=0;j<=m-1;++j) a[i][j+1]=int(s[j])-48;
    }
    for (int i=1;i<=n;++i)
    {   int nmax=0; int c=1;
        for (int j=1;j<=m;++j)
        if (a[j][i]>nmax)
        {   nmax=a[j][i]; c=1;    }
        else if (a[j][i]==nmax) c++;
        if (c==1) d++;
    }
    cout<<d;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n,m,f[107];
char a[107][107];
int main()
{   freopen("A.inp","r",stdin);
    freopen("A.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin>>n>>m;
    memset(f,0,sizeof(f));
    int ans=0;
    for (int i=1;i<=n;++i)
    for (int j=1;j<=m;++j)
    cin>>a[i][j];
    for (int i=1;i<=m;++i)
    {   int k=0;
        for (int j=1;j<=n;++j)
        if (int(a[j][i])>k) k=int(a[j][i]);
        for (int j=1;j<=n;++j)
        if (int(a[j][i])==k) f[j]=1;
    }
    for (int i=1;i<=n;++i)
    if (f[i]==1) ans++;
    cout<<ans;
    return 0;
}


#include<iostream>
#include<string>
#include<set>
using namespace std;

int main()
{
    int n,m,in,ma=-5554;
    set<int>p;
    string s[101];
    cin>>n>>m;
    for(int i=0;i<n;i++)
    cin>>s[i];
    for(int i=0;i<n;i++)
    {
    ma=0;
    for(int j=0;j<n;j++)
    {
    if(s[j][i]>ma)
    {
        ma=s[j][i];
        in=j;
    }
    }
    p.insert(in);
    }
    cout<<p.size()<<endl;
    //system("pause");
    return 0;
}


#include<iostream>
#include<string>
#include<set>
using namespace std;

int main()
{
    int n,m,in;
    set<int>p;
    string s[101];
    cin>>n>>m;
    for(int i=0;i<n;i++)
    cin>>s[i];
    for(int l=0;l<n;l++)
    for(int i=0;i<m;i++)
    for(int j=0;j<n;j++)
    if(s[j][i]>s[l][i])
        in=i;
    p.insert(in);
    }
    }
    cout<<p.size()<<endl;
    system("pause");
    return 0;
}
#include<iostream>
#include<string>
#include<set>
using namespace std;

int main()
{
    int n,m,in;
    set<int>p;
    string s[101];
    cin>>n>>m;
    for(int i=0;i<n;i++)
    cin>>s[i];
    for(int l=0;l<n;l++)
    for(int i=0;i<m;i++)
    for(int j=0;j<n;j++)
    if(s[j][i]>s[l][i])
        in=i;
    p.insert(in);
    }
    }
    cout<<p.size()<<endl;
    system("pause");
    return 0;
}


#include<iostream>
#include<string>
#include<set>
using namespace std;

int main()
{
    int n,m,in,ma;
    set<int>p;
    string s[101];
    cin>>n>>m;
    for(int i=0;i<n;i++)
    cin>>s[i];
    for(int i=0;i<n;i++)
    {
    ma=0;
    for(int j=0;j<n;j++)
    {
    if(s[i][i]>s[j][j])
    {
        ma=s[i][i];
        in=i;
    }
    else
    {
        ma=s[j][j];
        in=j;
    }
    }
    p.insert(in);
    }
    cout<<p.size()<<endl;
    //system("pause");
    return 0;
}


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

int main()
{
    int n,m,k=0,j=0;
    string s[101];
    cin>>n>>m;
    for(int i=0;i<n;i++)
    cin>>s[i];
    if(n==2&&m==1)
    {
    cout<<"1"<<endl;
    return 0;
    }

    for(int i=0;i<n;i++)
    { for(int o=0;o<m;o++)
    {
         if(i!=o)
     if(s[i][i]>=s[i][o])
      k++;
    }
      if(k>=n-1)
          j++;
    }
    cout<<j<<endl;
    //system("pause");
    return 0;
}


#include<iostream>
#include<string>
#include<set>
using namespace std;

int main()
{
    int n,m,in,k=0;
    char ma;
    set<int>p;
    string s[101];
    cin>>n>>m;
    for(int i=0;i<n;i++)
    cin>>s[i];
    for(int i=0;i<n;i++)
    {
    ma=0;
    for(int j=0;j<n;j++)
    {
    if(s[j][i]>ma)
    {
        ma=s[j][i];
        in=j;
    }
    if(j+1>=n)
    {
    if(s[i][j]==s[n-1][i])
    k++;
    }
    else
    {
    if(s[i][j]==s[j+1][i])
    k++;
    }
    }
    p.insert(in);
    }

    cout<<p.size()+k/n<<endl;
    //system("pause");
    return 0;
}


#include<iostream>
#include<string>
#include<set>
using namespace std;

int main()
{
    int n,m,in,ma;
    set<int>p;
    string s[101];
    cin>>n>>m;
    for(int i=0;i<n;i++)
    cin>>s[i];
    for(int i=0;i<n;i++)
    {
    ma=0;
    for(int j=0;j<n;j++)
    {
    if(s[i][i]>s[j][i])
    {
        ma=s[i][i];
        in=i;
    }
    else
    {
        ma=s[j][j];
        in=j;
    }
    }
    p.insert(in);
    }
    cout<<p.size()<<endl;
    //system("pause");
    return 0;
}


#include<iostream>
#include<string>
#include<set>
using namespace std;

int main()
{
    int n,m,in,k=0;
    char ma;
    set<int>p;
    string s[101];
    cin>>n>>m;
    for(int i=0;i<n;i++)
    cin>>s[i];
    for(int i=0;i<n;i++)
    {
    ma=0;
    for(int j=0;j<n;j++)
    {
    if(s[j][i]>ma)
    {
        ma=s[j][i];
        in=j;
    }
    }
    p.insert(in);
    }

    cout<<p.size()+k/n<<endl;
    //system("pause");
    return 0;
}


#include<iostream>
#include<string>
#include<set>
using namespace std;

int main()
{
    int n,m,in,k=0;
    char ma;
    set<int>p;
    string s[101];
    cin>>n>>m;
    for(int i=0;i<n;i++)
    cin>>s[i];
    for(int i=0;i<n;i++)
    {
    ma=0;
    for(int j=0;j<n;j++)
    {
    if(s[j][i]>ma)
    {
        ma=s[j][i];
        in=j;
    }
    if(s[i][j]==s[i][j+1])
        k++;
    }
    p.insert(in);
    }

    cout<<p.size()+k/n<<endl;
    //system("pause");
    return 0;
}


#include<iostream>
#include<string>
#include<set>
using namespace std;

int main()
{
    int n,m,in,k=0;
    char ma;
    set<int>p;
    string s[101];
    cin>>n>>m;
    for(int i=0;i<n;i++)
    cin>>s[i];
    for(int i=0;i<n;i++)
    {
    ma=0;
    for(int j=0;j<n;j++)
    {
    if(s[j][i]>ma)
    {
        ma=s[j][i];
        in=i;
    }
    }
    p.insert(in);
    }

    cout<<p.size()+k/n<<endl;
    //system("pause");
    return 0;
}


#include<iostream>
#include<string>
#include<set>
using namespace std;

int main()
{
    int n,m,in,k=0;
    char ma;
    set<int>p;
    string s[101];
    cin>>n>>m;
    for(int i=0;i<n;i++)
    cin>>s[i];
    for(int l=0;l<n;l++)
    for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
    if(s[j][i]>s[l][i])
        in=i;
    p.insert(in);
    }
    }
    cout<<p.size()+k/n<<endl;
    //system("pause");
    return 0;
}


#include<iostream>
#include<string>
#include<set>
using namespace std;

int main()
{
    int n,m,in,ma=-5554;
    set<int>p;
    string s[101];
    cin>>n>>m;
    for(int i=0;i<n;i++)
    cin>>s[i];
    for(int i=0;i<n;i++)
    {
    ma=0;
    for(int j=0;j<n;j++)
    {
    if(s[j][i]>=ma)
    {
        ma=s[j][i];
        in=j;
    }
    }
    p.insert(in);
    }
    cout<<p.size()<<endl;
    //system("pause");
    return 0;
}


#include<iostream>
#include<string>
#include<set>
using namespace std;

int main()
{
    int n,m,in,k=0;
    char ma;
    set<int>p;
    string s[101];
    cin>>n>>m;
    for(int i=0;i<n;i++)
    cin>>s[i];
    if(n==1&&s[0][1]!=s[0][0])
    {
        cout<<"1"<<endl;
        return 0;
    }
    for(int i=0;i<n;i++)
    {
    ma=0;
    for(int j=0;j<n;j++)
    {
    if(s[j][i]>ma)
    {
        ma=s[j][i];
        in=j;
    }
    if(j+1>=n)
    {
    if(s[i][j]==s[n-1][i])
    k++;
    }
    else
    {
    if(s[i][j]==s[j+1][i])
    k++;
    }
    }
    p.insert(in);
    }

    cout<<p.size()+k/n<<endl;
    //system("pause");
    return 0;
}


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

int main()
{
    int n,m,k=0,j=0;
    string s[101];
    cin>>n>>m;
    for(int i=0;i<n;i++)
    cin>>s[i];
    for(int i=0;i<n;i++)
    { for(int o=0;o<m;o++)
    {
         if(i!=o)
     if(s[i][i]>=s[i][o])
      k++;
    }
      if(k>=n-1)
          j++;
    }
    cout<<j<<endl;
    //system("pause");
    return 0;
}


#include<iostream>
#include<string>
#include<set>
using namespace std;

int main()
{
    int n,m,in;
    set<int>p;
    string s[101];
    cin>>n>>m;
    for(int i=0;i<n;i++)
    cin>>s[i];
    for(int l=0;l<n;l++)
    {
    for(int i=0;i<m;i++)
    for(int j=0;j<n;j++)
    if(s[j][i]>s[l][i])
        in=i;
    p.insert(in);
    }
    cout<<p.size()<<endl;

    return 0;
}


#include<iostream>
#include<string>
#include<set>
using namespace std;

int main()
{
    int n,m,ans=0;
    set<int>p;
    string a[101];
    cin>>n>>m;
    for(int i=0;i<n;i++)
    cin>>a[i];
    for (int i = 0; i < n; ++i)
    {
    bool wasBest = false;
    for(int j = 0; j < m; ++j)
    {
    bool isBest = true;
    for(int k = 0; k < n; ++k)
    if(a[k][j] > a[i][j])
    isBest = false;
    if(isBest)
    wasBest = true;
    }
    if(wasBest)
    ans++;
    }
    cout<<ans<<endl;
    return 0;
}


    #include <bits/stdc++.h>
using namespace std;
int a[110][110];
bool f[110];
int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    for(int i = 0; i < n; i ++){
        for(int j = 0; j < m; j ++){
            scanf("%1d", &a[i][j]);
        }
    }
    for(int j = 0; j < m; j ++){
        int maxn = -1;
        for(int i = 0; i < n; i ++){
            if(a[i][j] > maxn) maxn = a[i][j];
        }
        for(int i = 0; i < n; i ++){
            if(a[i][j] == maxn) f[i] = 1;
        }
    }
    int ans = 0;
    for(int i = 0; i < n; i ++){
        if(f[i]) ans ++;
    }
    printf("%d", ans);
}


#include <bits/stdc++.h>
using namespace std;

int main() {
//	freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	int n, m; cin >> n >> m;
	int a[n][m];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> a[i][j];
		}
	}
	set<int> s[m];
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < n; j++) {
			s[i].insert(a[j][i]);
		}
	}
	int b[m];
	for (int i = 0; i < m; i++) {
		b[i] = *s[i].rbegin();
	}
	bool chk[n] = {0};
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (b[j] == a[i][j]) {
				chk[i] = 1; continue;
			}
		}
	}
	int cnt = 0;
	for (int i = 0; i < m; i++) {
		if (chk[i] == 1) cnt++;
	}
	cout << cnt << endl;
	return 0;
}


    #include <bits/stdc++.h>
using namespace std;

const int N = 105;

int n, m;
char s[N][N];
bool vis[N];

int main() {
	scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; i ++) scanf("%s", s[i]);
    for (int i = 0; i < m; i ++) {
        int mx = 0;
        for (int j = 1; j <= n; j ++) mx = max(mx, s[j][i]-'0');
		for (int j = 1; j <= n; j ++) if (mx + '0' == s[j][i]) vis[j] = 1;
    }
    int ans = 0;
    for (int i = 1; i <= n; i ++) if (vis[i]) ans ++;
    printf("%d\n", ans);
	return 0;
}


    #include <bits/stdc++.h>
using namespace std;

int main(){
	int n, m;
	string a[111];
	bool color[111];
	cin >> n >> m;
	for(int i = 0 ; i < n ;  i ++)cin >> a[i];
	for(int i = 0; i < m; i ++){
		int ss = 0;
		for(int j = 0 ; j < n ; j ++)ss = max(ss, a[j][i] - '0');
		for(int j = 0 ; j < n ; j ++){
			if(a[j][i] - '0' == ss)color[j] = 1;
		}
	}
	int res = 0;
	for(int i = 0 ; i < n ; i ++)
		if(color[i] == 1)res ++;
	cout << res;
}


    #include<bits/stdc++.h>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector <string> a(n);
    for(int i = 0; i < n; i ++) cin >> a[i];
    vector <int> b(n, 0);
    for(int i = 0; i < m; i ++) {
        int mx = -1;
        for(int j = 0; j < n; j ++) mx = max(mx, (int)a[j][i]);
        for(int j = 0; j < n; j ++) if(a[j][i] == mx) b[j] = 1;
    }
    int ans = 0;
    for(int i = 0; i < n; i ++) ans += b[i];
    cout << ans << endl;
}


    #include <bits/stdc++.h>
using namespace std;
#define N 103
int b[N] = {},a[N][N],mx[N];
char c[N][N];
int main(){
	int n,m,sum = 0;
	fill(mx,mx + N,-1);
	scanf("%d%d",&n,&m);
	for(int i = 0; i < n; i++){
		scanf("%s",&c[i]);}
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			a[i][j] = c[i][j]- '0';
			if(mx[j] < a[i][j]) mx[j] = a[i][j];}}
	for(int i = 0; i < m; i++)
		for(int j = 0; j < n; j++){
			if(a[j][i] == mx[i]) b[j] = 1;}
	for(int i = 0; i < n; i++)
		if(b[i] >= 1) sum++;
	printf("%d\n",sum);
}


#include <bits/stdc++.h>
using namespace std;

int main() {
//	freopen("in.txt", "r", stdin);
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	int n, m; cin >> n >> m;
	set<int> s[m];
	int b[m];
	string c[n];
	for (int i = 0; i < n; i++) {
		cin >> c[i];
		for (int j = 0; j < m; j++) {
			s[j].insert(c[i][j] - '0');
		}
	}
	for (int i = 0; i < m; i++) {
		b[i] = *s[i].rbegin();
	}
	bool chk[n] = {0};
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if ((c[i][j] - '0') == b[j]) {
				chk[i] = 1; break;
			}
		}
	}
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (chk[i] == 1) cnt++;
	}
	cout << cnt << endl;
	return 0;
}


    #include <bits/stdc++.h>
using namespace std;

const int N = 110;

set<int> S[N];

int main() {
//	freopen("in.txt", "r", stdin);
	int n, m; cin >> n >> m;
	for (int i = 0; i < n; i++) {
		int a, fn = m-1, _m = m; cin >> a;
		while (_m--) {
			S[fn--].insert(a % 10);
			a /= 10;
		}
	}
	int b[m];
	for (int i = 0; i < m; i++) {
		b[i] = S[i].size();
	}
	sort(b, b + m);
	cout << b[m-1] << endl;
}


    #include <bits/stdc++.h>
using namespace std;
#define N 103
int b[N] = {},a[N][N],mx[N];
char c[N][N];
int main(){
	int n,m,sum = 0;
	fill(mx,mx + N,-1);
	scanf("%d %d",&n,&m);
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			scanf("%1d",&a[i][j]);
			if(mx[j] < a[i][j]) mx[j] = a[i][j];}}
	for(int i = 0; i < m; i++)
		for(int j = 0; j < n; j++){
			if(a[j][i] == mx[i]) b[j] = 1;}
	for(int i = 0; i < n; i++)
		if(b[i] >= 1) sum++;
	printf("%d\n",sum);
}


#include <stdio.h>
#include <iostream>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <string.h>
#include <fstream>

using namespace std;
int gcd(int a,int b)
{
	if(b==0) return a;
	return gcd(b,a%b);
}
string s[100]="";
bool mx[100]={0};
int main()
{

	int n,m,ans=0,max=0,maxi=0;
	cin>>n>>m;
	for(int i=0;i<n;i++)
		cin>>s[i];
	for(int i=0;i<m;i++)
	{
		max=0;
		for(int j=0;j<n;j++)
		{
			if(max < s[j][i]-48 )
				max=s[j][i]-48,maxi=j;
				else if(max == s[j][i]-48 && !mx[j])
				max=s[j][i]-48,maxi=j;

		}
		mx[maxi]=1;
		max=  maxi= 0;
	}
	for(int i=0;i<100;i++)
			if(mx[i]) ans++;
	cout<<ans<<endl;

}


#include<stdio.h>
#include<vector>
using namespace std;
vector<int> v[100001];
int c[100001];
int deg[100001];
int anss[100001];
int main()
{
    int n;
    scanf("%d",&n);
    int uu,vv;
    for(int i=1;i<n;i++)
    {
        scanf("%d%d",&uu,&vv);
        v[uu].push_back(vv);
        v[vv].push_back(uu);
        deg[uu]++;
        deg[vv]++;
    }
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&c[i]);
    }
    int ans=-1;
    int ans1=-1,ans2=-1;
    int ok=1;
    for(int i=1;i<=n;i++)
    {
        if(deg[i]==1)continue;
        int len=v[i].size();
        int dif=-1;
        int j;
        for(j=0;j<len;j++)
        {
            int now=v[i][j];
            if(c[now]!=c[i])
            {
                if(dif!=-1)
                {
                    if(ans!=-1)ok=0;
                    else if(ans1!=-1&&ans2!=-1&&(ans1!=i||ans2!=i))ok=0;
                    else ans=i;
                    break;
                }
                else dif=now;
            }
        }
        if(!ok)break;
        if(j==len)
        {
            if(ans!=-1&&dif!=ans)
            {
                ok=0;
                break;
            }
            else if(ans1==-1&&ans2==-1)
            {
                ans1=i;
                ans2=dif;
            }
            else if(ans1!=i&&ans2!=i)
            {
                ok=0;
                break;
            }
        }
    }
    if(!ok)printf("NO\n");
    else
    {
        printf("YES\n");
        if(ans!=-1)printf("%d\n",ans);
        else if(ans1!=-1)printf("%d\n",ans1);
        else printf("1\n");
    }
    return 0;
}


#include<stdio.h>
#include<vector>
using namespace std;
vector<int> v[100001];
int c[100001];
int deg[100001];
int anss[100001];
int main()
{
    int n;
    scanf("%d",&n);
    int uu,vv;
    for(int i=1;i<n;i++)
    {
        scanf("%d%d",&uu,&vv);
        v[uu].push_back(vv);
        v[vv].push_back(uu);
        deg[uu]++;
        deg[vv]++;
    }
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&c[i]);
    }
    int ans=-1;
    int ans1=-1,ans2=-1;
    int ok=1;
    for(int i=1;i<=n;i++)
    {
        if(deg[i]==1)continue;
        int len=v[i].size();
        int dif=-1;
        int j;
        for(j=0;j<len;j++)
        {
            int now=v[i][j];
            if(c[now]!=c[i])
            {
                if(dif!=-1)
                {
                    if(ans!=-1)ok=0;
                    else if(ans1!=-1&&ans2!=-1&&ans1!=i&&ans2!=i)ok=0;
                    else ans=i;
                    break;
                }
                else dif=now;
            }
        }
        if(!ok)break;
        if(j==len)
        {
            if(dif==-1)continue;
            if(ans!=-1&&dif!=ans)
            {
                ok=0;
                break;
            }
            else if(ans1==-1&&ans2==-1)
            {
                ans1=i;
                ans2=dif;
            }
            else if(ans1!=i&&ans2!=i)
            {
                ok=0;
                break;
            }
        }
    }
    if(!ok)printf("NO\n");
    else
    {
        printf("YES\n");
        if(ans!=-1)printf("%d\n",ans);
        else if(ans1!=-1)printf("%d\n",ans1);
        else printf("1\n");
    }
    return 0;
}


#include<stdio.h>
#include<vector>
using namespace std;
vector<int> v[100001];
int c[100001];
int deg[100001];
int anss[100001];
int main()
{
    int n;
    scanf("%d",&n);
    int uu,vv;
    for(int i=1;i<n;i++)
    {
        scanf("%d%d",&uu,&vv);
        v[uu].push_back(vv);
        v[vv].push_back(uu);
        deg[uu]++;
        deg[vv]++;
    }
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&c[i]);
    }
    int ans=-1;
    int ans1=-1,ans2=-1;
    int ok=1;
    for(int i=1;i<=n;i++)
    {
        if(deg[i]==1)continue;
        int len=v[i].size();
        int dif=-1;
        int j;
        for(j=0;j<len;j++)
        {
            int now=v[i][j];
            if(c[now]!=c[i])
            {
                if(dif!=-1)
                {
                    if(ans!=-1)ok=0;
                    else ans=i;
                    break;
                }
                else dif=now;
            }
        }
        if(!ok)break;
        if(j==len)
        {
            if(ans!=-1&&dif!=ans)
            {
                ok=0;
                break;
            }
            else if(ans1==-1&&ans2==-1)
            {
                ans1=i;
                ans2=dif;
            }
            else if(ans1!=i&&ans2!=i)
            {
                ok=0;
                break;
            }
        }
    }
    if(!ok)printf("NO\n");
    else
    {
        printf("YES\n");
        if(ans!=-1)printf("%d\n",ans);
        else if(ans1!=-1)printf("%d\n",ans1);
        else printf("1\n");
    }
    return 0;
}


#include<stdio.h>
#include<vector>
using namespace std;
vector<int> v[100001];
int c[100001];
int deg[100001];
int anss[100001];
int main()
{
    int n;
    scanf("%d",&n);
    int uu,vv;
    for(int i=1;i<n;i++)
    {
        scanf("%d%d",&uu,&vv);
        v[uu].push_back(vv);
        v[vv].push_back(uu);
        deg[uu]++;
        deg[vv]++;
    }
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&c[i]);
    }
    int ans=-1;
    int ans1=-1,ans2=-1;
    int ok=1;
    for(int i=1;i<=n;i++)
    {
        if(deg[i]==1)continue;
        int len=v[i].size();
        int dif=-1;
        int j;
        for(j=0;j<len;j++)
        {
            int now=v[i][j];
            if(c[now]!=c[i])
            {
                if(dif!=-1)
                {
                    if(ans!=-1)ok=0;
                    else if(ans1!=-1&&ans2!=-1&&ans1!=i&&ans2!=i)ok=0;
                    else ans=i;
                    break;
                }
                else dif=now;
            }
        }
        if(!ok)break;
        if(j==len)
        {
            if(ans!=-1&&dif!=ans)
            {
                ok=0;
                break;
            }
            else if(ans1==-1&&ans2==-1)
            {
                ans1=i;
                ans2=dif;
            }
            else if(ans1!=i&&ans2!=i)
            {
                ok=0;
                break;
            }
        }
    }
    if(!ok)printf("NO\n");
    else
    {
        printf("YES\n");
        if(ans!=-1)printf("%d\n",ans);
        else if(ans1!=-1)printf("%d\n",ans1);
        else printf("1\n");
    }
    return 0;
}


#include<stdio.h>
#include<vector>
using namespace std;
vector<int> v[100001];
int c[100001];
int deg[100001];
struct dui
{
    int a;
    int b;
};
dui d[100005];
int main()
{
    int n;
    scanf("%d",&n);
    int uu,vv;
    for(int i=1;i<n;i++)
    {
        scanf("%d%d",&uu,&vv);
        v[uu].push_back(vv);
        v[vv].push_back(uu);
        deg[uu]++;
        deg[vv]++;
    }
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&c[i]);
    }
    int ans=-1;
    int ans1=-1,ans2=-1;
    int ok=1;
    int l=0;
    for(int i=1;i<=n;i++)
    {
        //if(deg[i]==1)continue;
        int len=v[i].size();
        int dif=-1;
        int j;
        for(j=0;j<len;j++)
        {
            int now=v[i][j];
            if(c[now]!=c[i])
            {
                if(dif!=-1)
                {
                    if(ans!=-1)ok=0;
                    else ans=i;
                    break;
                }
                else dif=now;
            }
        }
        if(!ok)break;
        if(j==len)
        {
            if(dif==-1)continue;
            d[l].a=i;
            d[l].b=dif;
            l++;
        }
    }
    if(ans==-1&&l>2)ok=0;
    else if(ans!=-1)
    {
        for(int i=0;i<l;i++)
        {
            if(d[i].a!=ans&&d[i].b!=ans)
            {
                ok=0;
                break;
            }
        }
    }
    if(!ok)printf("NO\n");
    else
    {
        printf("YES\n");
        if(ans!=-1)printf("%d\n",ans);
        else if(l>0)printf("%d\n",d[0].a);
        else printf("1\n");
    }
    return 0;
}


#include<stdio.h>
#include<vector>
using namespace std;
vector<int> v[100001];
int c[100001];
int deg[100001];
struct dui
{
    int a;
    int b;
};
dui d[100005];
int main()
{
    int n;
    scanf("%d",&n);
    int uu,vv;
    for(int i=1;i<n;i++)
    {
        scanf("%d%d",&uu,&vv);
        v[uu].push_back(vv);
        v[vv].push_back(uu);
        deg[uu]++;
        deg[vv]++;
    }
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&c[i]);
    }
    int ans=-1;
    int ans1=-1,ans2=-1;
    int ok=1;
    int l=0;
    for(int i=1;i<=n;i++)
    {
        if(deg[i]==1)continue;
        int len=v[i].size();
        int dif=-1;
        int j;
        for(j=0;j<len;j++)
        {
            int now=v[i][j];
            if(c[now]!=c[i])
            {
                if(dif!=-1)
                {
                    if(ans!=-1)ok=0;
                    else ans=i;
                    break;
                }
                else dif=now;
            }
        }
        if(!ok)break;
        if(j==len)
        {
            if(dif==-1)continue;
            d[l].a=i;
            d[l].b=dif;
            l++;
        }
    }
    if(ans==-1&&l>2)ok=0;
    else if(ans!=-1)
    {
        for(int i=0;i<l;i++)
        {
            if(d[i].a!=ans&&d[i].b!=ans)
            {
                ok=0;
                break;
            }
        }
    }
    if(!ok)printf("NO\n");
    else
    {
        printf("YES\n");
        if(ans!=-1)printf("%d\n",ans);
        else if(l>0)printf("%d\n",d[0].a);
        else printf("1\n");
    }
    return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const int maxn=100001;

int n,c[maxn],sc[maxn];
vector<int> path[maxn];
int fa[maxn],u,v;

void buildtree(int p,int father)
{
	fa[p]=father;
	for(int i=0;i<path[p].size();i++)
	    if (path[p][i]!=father) buildtree(path[p][i],p);
	return;
}

void calc(int p)
{
	sc[p]=c[p];
	for(int i=0;i<path[p].size();i++)
	{
		if (path[p][i]==fa[p]) continue;
		calc(path[p][i]);
		if (sc[p]!=sc[path[p][i]]) sc[p]=-1;
	}
	return;
}

int answer(int p,int precolor)
{
	bool f=true;
	for(int i=0;i<path[p].size();i++)
	{
		if (path[p][i]==fa[p]) continue;
		if (sc[path[p][i]]==-1)
		{
			f=false;
			break;
		}
	}
	if (f) return p;

	int count=-1;
	for(int i=0;i<path[p].size();i++)
	{
		if (path[p][i]==fa[p]) continue;
		if (sc[path[p][i]]==-1)
		{
			if (count==-1) count=path[p][i];
			else
			{
				count=-2;
				break;
			}
		}
	}

	if (count==-2) return -1;
	if (precolor!=-1 && c[p]!=precolor) return -1;
	if (precolor==-1) precolor=c[p];
	for(int i=0;i<path[p].size();i++)
		if (path[p][i]!=count && path[p][i]!=fa[p])
		{
			if (precolor!=-1 && sc[path[p][i]]!=precolor)
			    return -1;
		}
	int ans=answer(count,precolor);
	return ans;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&u,&v);
		path[u].push_back(v);
		path[v].push_back(u);
	}
	for(int i=1;i<=n;i++)
	    scanf("%d",&c[i]);

	buildtree(1,1);
	calc(1);

	int ans=answer(1,-1);
	if (ans==-1) printf("NO\n");
	else printf("YES\n%d\n",ans);
	return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const int maxn=100001;

int n,c[maxn],sc[maxn];
vector<int> path[maxn];
int fa[maxn],u,v;

void buildtree(int p,int father)
{
	fa[p]=father;
	for(int i=0;i<path[p].size();i++)
	    if (path[p][i]!=father) buildtree(path[p][i],p);
	return;
}

void calc(int p)
{
	sc[p]=c[p];
	for(int i=0;i<path[p].size();i++)
	{
		if (path[p][i]==fa[p]) continue;
		calc(path[p][i]);
		if (sc[p]!=sc[path[p][i]]) sc[p]=-1;
	}
	return;
}

int answer(int p,int precolor)
{
	bool f=true;
	for(int i=0;i<path[p].size();i++)
	{
		if (path[p][i]==fa[p]) continue;
		if (sc[path[p][i]]==-1)
		{
			f=false;
			break;
		}
	}
	if (f) return p;

	int count=-1;
	for(int i=0;i<path[p].size();i++)
	{
		if (path[p][i]==fa[p]) continue;
		if (sc[path[p][i]]==-1)
		{
			if (count==-1) count=path[p][i];
			else
			{
				count=-2;
				break;
			}
		}
	}

	if (count==-2) return -1;
	if (precolor!=-1 && c[p]!=precolor) return -1;
	for(int i=0;i<path[p].size();i++)
		if (path[p][i]!=count)
		{
			if (precolor!=-1 && sc[path[p][i]]!=precolor)
			    return -1;
		}
	if (precolor==-1) precolor=c[p];
	int ans=answer(count,precolor);
	return ans;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&u,&v);
		path[u].push_back(v);
		path[v].push_back(u);
	}
	for(int i=1;i<=n;i++)
	    scanf("%d",&c[i]);

	buildtree(1,1);
	calc(1);

	int ans=answer(1,-1);
	if (ans==-1) printf("NO\n");
	else printf("YES\n%d\n",ans);
	return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const int maxn=100001;

int n,c[maxn],sc[maxn];
vector<int> path[maxn];
int fa[maxn],u,v;

void buildtree(int p,int father)
{
	fa[p]=father;
	for(int i=0;i<path[p].size();i++)
	    if (path[p][i]!=father) buildtree(path[p][i],p);
	return;
}

void calc(int p)
{
	sc[p]=c[p];
	for(int i=0;i<path[p].size();i++)
	{
		if (path[p][i]==fa[p]) continue;
		calc(path[p][i]);
		if (sc[p]!=sc[path[p][i]]) sc[p]=-1;
	}
	return;
}

int answer(int p,int precolor)
{
	bool f=true;
	for(int i=0;i<path[p].size();i++)
	{
		if (path[p][i]==fa[p]) continue;
		if (sc[path[p][i]]==-1)
		{
			f=false;
			break;
		}
	}
	if (f) return p;

	int count=-1;
	for(int i=0;i<path[p].size();i++)
	{
		if (path[p][i]==fa[p]) continue;
		if (sc[path[p][i]]==-1)
		{
			if (count==-1) count=path[p][i];
			else
			{
				count=-2;
				break;
			}
		}
	}

	if (count==-2) return -1;
	if (precolor!=-1 && c[p]!=precolor) return -1;
	for(int i=0;i<path[p].size();i++)
		if (path[p][i]!=count && path[p][i]!=fa[p])
		{
			if (precolor!=-1 && sc[path[p][i]]!=precolor)
			    return -1;
		}
	if (precolor==-1) precolor=c[p];
	int ans=answer(count,precolor);
	return ans;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&u,&v);
		path[u].push_back(v);
		path[v].push_back(u);
	}
	for(int i=1;i<=n;i++)
	    scanf("%d",&c[i]);

	buildtree(1,1);
	calc(1);

	int ans=answer(1,-1);
	if (ans==-1) printf("NO\n");
	else printf("YES\n%d\n",ans);
	return 0;
}


#include<cstdio>

typedef long long ll;
template<class T>
inline void read(T&x)
{
	x=0;bool f=0;char c=getchar();
	while((c<'0'||c>'9')&&c!='-') c=getchar();if(c=='-')f=1, c=getchar();
	while(c>='0'&&c<='9'){x=x*10+c-'0'; c=getchar();}
	x=f?-x:x;
}
const int MAXN(100010);
struct Node{int nd,nx;}bot[MAXN<<1];int tot,first[MAXN];
void add(int a,int b){bot[++tot]=(Node){b,first[a]};first[a]=tot;}
int n,a,b,col[MAXN],Eu[MAXN],size[MAXN],num[MAXN],last[MAXN],cnt,Ans;
bool dif[MAXN];
void DFS(int x,int f)
{
	Eu[x]=++cnt; num[cnt]=x;size[x]=1;
	for(int v=first[x];v;v=bot[v].nx)
	if(bot[v].nd!=f)
	{
		DFS(bot[v].nd,x); size[x]+=size[bot[v].nd];
		dif[x]|=dif[bot[v].nd]|(col[x]!=col[bot[v].nd]);
	}
}
void DP(int x,int f)
{
	bool bf=false;
	for(int v=first[x];v;v=bot[v].nx)
	if(bot[v].nd!=f)
	{
		DP(bot[v].nd,x);
		bf|=dif[bot[v].nd];
	}
	if(!bf)
	{
//		fprintf(stderr,"%d\n",x);
		int L=Eu[x]-1,R=Eu[x]+size[x];
//		fprintf(stderr,"%d %d\n",L,R);
		if((!L||last[1]>=L)&&(R>n||last[R]>=n)&&(!L||R>n||col[num[1]]==col[num[n]]))Ans=x;
	}
}
int main()
{
//	freopen("C.in","r",stdin);
	read(n);
	for(int i=1;i<n;i++)
	{
		read(a);read(b);
		add(a,b);add(b,a);
	}
	for(int i=1;i<=n;i++)read(col[i]);
	DFS(1,0);
	for(int i=n;i>=1;i--)last[i]=(col[num[i]]==col[num[i+1]])?last[i+1]:i;
	DP(1,0);
	if(!Ans)printf("NO");
	else printf("YES\n%d\n",Ans);
	return 0;
}


#include<cstdio>

typedef long long ll;
template<class T>
inline void read(T&x)
{
	x=0;bool f=0;char c=getchar();
	while((c<'0'||c>'9')&&c!='-') c=getchar();if(c=='-')f=1, c=getchar();
	while(c>='0'&&c<='9'){x=x*10+c-'0'; c=getchar();}
	x=f?-x:x;
}
const int MAXN(100010);
struct Node{int nd,nx;}bot[MAXN<<1];int tot,first[MAXN];
void add(int a,int b){bot[++tot]=(Node){b,first[a]};first[a]=tot;}
int n,a,b,col[MAXN],Eu[MAXN],size[MAXN],num[MAXN],last[MAXN],cnt,Ans;
bool dif[MAXN];
void DFS(int x,int f)
{
	Eu[x]=++cnt; num[cnt]=x;size[x]=1;
	for(int v=first[x];v;v=bot[v].nx)
	if(bot[v].nd!=f)
	{
		DFS(bot[v].nd,x);size[x]+=size[bot[v].nd];
		dif[x]|=dif[bot[v].nd]|(col[x]!=col[bot[v].nd]);
	}
}
void DP(int x,int f)
{
	bool bf=false;
	for(int v=first[x];v;v=bot[v].nx)
	if(bot[v].nd!=f)
	{
		DP(bot[v].nd,x);
		bf|=dif[bot[v].nd];
	}
	if(!bf)
	{
//		fprintf(stderr,"%d\n",x);
		int L=Eu[x],R=Eu[x]+size[x]-1;
//		fprintf(stderr,"%d %d\n",L,R);
		if(last[R]>=n&&last[1]>=L-1)Ans=x;
	}
}
int main()
{
//	freopen("C.in","r",stdin);
	read(n);
	for(int i=1;i<n;i++)
	{
		read(a);read(b);
		add(a,b);add(b,a);
	}
	for(int i=1;i<=n;i++)read(col[i]);
	DFS(1,0);
	for(int i=n;i>=1;i--)last[i]=(col[num[i]]==col[num[i+1]])?last[i+1]:i;
	DP(1,0);
	if(!Ans)printf("NO");
	else printf("YES\n%d\n",Ans);
	return 0;
}


#include<cstdio>

typedef long long ll;
template<class T>
inline void read(T&x)
{
	x=0;bool f=0;char c=getchar();
	while((c<'0'||c>'9')&&c!='-') c=getchar();if(c=='-')f=1, c=getchar();
	while(c>='0'&&c<='9'){x=x*10+c-'0'; c=getchar();}
	x=f?-x:x;
}
const int MAXN(100010);
struct Node{int nd,nx;}bot[MAXN<<1];int tot,first[MAXN];
void add(int a,int b){bot[++tot]=(Node){b,first[a]};first[a]=tot;}
int n,a,b,col[MAXN],Eu[MAXN],size[MAXN],num[MAXN],last[MAXN],cnt,Ans;
bool dif[MAXN];
void DFS(int x,int f)
{
	Eu[x]=++cnt; num[cnt]=x;size[x]=1;
	for(int v=first[x];v;v=bot[v].nx)
	if(bot[v].nd!=f)
	{
		DFS(bot[v].nd,x); size[x]+=size[bot[v].nd];
		dif[x]|=dif[bot[v].nd]|(col[x]!=col[bot[v].nd]);
	}
}
void DP(int x,int f)
{
	bool bf=false;
	for(int v=first[x];v;v=bot[v].nx)
	if(bot[v].nd!=f)
	{
		DP(bot[v].nd,x);
		bf|=dif[bot[v].nd];
	}
	if(!bf)
	{
//		fprintf(stderr,"%d\n",x);
		int L=Eu[x],R=Eu[x]+size[x]-1;
//		fprintf(stderr,"%d %d\n",L,R);
		if(last[R]>=n&&last[1]>=L-1&&col[num[1]]==col[num[n]])Ans=x;
	}
}
int main()
{
	read(n);
	for(int i=1;i<n;i++)
	{
		read(a);read(b);
		add(a,b);add(b,a);
	}
	for(int i=1;i<=n;i++)read(col[i]);
	DFS(1,0);
	for(int i=n;i>=1;i--)last[i]=(col[num[i]]==col[num[i+1]])?last[i+1]:i;
	DP(1,0);
	if(!Ans)printf("NO");
	else printf("YES\n%d\n",Ans);
	return 0;
}


#include<cstdio>

typedef long long ll;
template<class T>
inline void read(T&x)
{
	x=0;bool f=0;char c=getchar();
	while((c<'0'||c>'9')&&c!='-') c=getchar();if(c=='-')f=1, c=getchar();
	while(c>='0'&&c<='9'){x=x*10+c-'0'; c=getchar();}
	x=f?-x:x;
}
const int MAXN(100010);
struct Node{int nd,nx;}bot[MAXN<<1];int tot,first[MAXN];
void add(int a,int b){bot[++tot]=(Node){b,first[a]};first[a]=tot;}
int n,a,b,col[MAXN],Eu[MAXN],size[MAXN],num[MAXN],last[MAXN],cnt,Ans;
bool dif[MAXN];
void DFS(int x,int f)
{
	Eu[x]=++cnt; num[cnt]=x;size[x]=1;
	for(int v=first[x];v;v=bot[v].nx)
	if(bot[v].nd!=f)
	{
		DFS(bot[v].nd,x); size[x]+=size[bot[v].nd];
		dif[x]|=dif[bot[v].nd]|(col[x]!=col[bot[v].nd]);
	}
}
void DP(int x,int f)
{
	bool bf=false;
	for(int v=first[x];v;v=bot[v].nx)
	if(bot[v].nd!=f)
	{
		DP(bot[v].nd,x);
		bf|=dif[bot[v].nd];
	}
	if(!bf)
	{
//		fprintf(stderr,"%d\n",x);
		int L=Eu[x]-1,R=Eu[x]+size[x];
//		fprintf(stderr,"%d %d\n",L,R);
		if((!L||last[1]>=L-1)&&(R>n||last[R]>=n)&&(!L||R>n||col[num[1]]==col[num[n]]))Ans=x;
	}
}
int main()
{
//	freopen("C.in","r",stdin);
	read(n);
	for(int i=1;i<n;i++)
	{
		read(a);read(b);
		add(a,b);add(b,a);
	}
	for(int i=1;i<=n;i++)read(col[i]);
	DFS(1,0);
	for(int i=n;i>=1;i--)last[i]=(col[num[i]]==col[num[i+1]])?last[i+1]:i;
	DP(1,0);
	if(!Ans)printf("NO");
	else printf("YES\n%d\n",Ans);
	return 0;
}


#include<cstdio>

typedef long long ll;
template<class T>
inline void read(T&x)
{
	x=0;bool f=0;char c=getchar();
	while((c<'0'||c>'9')&&c!='-') c=getchar();if(c=='-')f=1, c=getchar();
	while(c>='0'&&c<='9'){x=x*10+c-'0'; c=getchar();}
	x=f?-x:x;
}
const int MAXN(100010);
struct Node{int nd,nx;}bot[MAXN<<1];int tot,first[MAXN];
void add(int a,int b){bot[++tot]=(Node){b,first[a]};first[a]=tot;}
int n,a,b,col[MAXN],Eu[MAXN],size[MAXN],num[MAXN],last[MAXN],cnt,Ans;
bool dif[MAXN];
void DFS(int x,int f)
{
	Eu[x]=++cnt; num[cnt]=x;size[x]=1;
	for(int v=first[x];v;v=bot[v].nx)
	if(bot[v].nd!=f)
	{
		DFS(bot[v].nd,x);size[x]+=size[bot[v].nd];
		dif[x]|=dif[bot[v].nd]|(col[x]!=col[bot[v].nd]);
	}
}
void DP(int x,int f)
{
	bool bf=false;
	for(int v=first[x];v;v=bot[v].nx)
	if(bot[v].nd!=f)
	{
		DP(bot[v].nd,x);
		bf|=dif[bot[v].nd];
	}
	if(!bf)
	{
//		fprintf(stderr,"%d\n",x);
		int L=Eu[x],R=Eu[x]+size[x]-1;
//		fprintf(stderr,"%d %d\n",L,R);
		if(last[R]>=n&&last[1]>=L-1)Ans=x;
	}
}
int main()
{
//	freopen("C.in","r",stdin);
	read(n);
	for(int i=1;i<n;i++)
	{
		read(a);read(b);
		add(a,b);add(b,a);
	}
	for(int i=1;i<=n;i++)read(col[i]);
	DFS(1,0);
	for(int i=n;i>=1;i--)last[i]=(col[num[i]]==col[num[i+1]])?last[i+1]:i;
	DP(1,0);
	if(!Ans)printf("No");
	else printf("Yes\n%d\n",Ans);
	return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
struct node
{
	__int64 u, v;
}edge[100000*4+10];
int main()
{
	__int64 n;
	scanf("%I64d", &n);
	__int64 i, j, color[100000+5];
	for(i = 1; i < n; i++) scanf("%I64d%I64d", &edge[i].u, &edge[i].v);
	for(i = 1; i <= n; i++) scanf("%I64d", &color[i]);
	//printf("**\n");
	__int64 cnt[n+5], alldif = 0;
	memset(cnt, 0, sizeof(cnt));
	for(i = 1; i < n; i++)
	{
		if(color[edge[i].u] != color[edge[i].v])
		{
			alldif++;
			cnt[edge[i].u]++;
			cnt[edge[i].v]++;
		}
	}
	__int64 p = 0, pos[n+5];
	for(i = 1; i <= n; i++)
	{
		if(cnt[i] == alldif) pos[p++]=i;
		//printf("%d\n", cnt[i]);
	}
	if(!p) printf("NO\n");
	else
	{
		printf("YES\n");
		for(i = 0; i < p; i++) printf("%I64d ", pos[i]);
	}
	return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
struct node
{
	__int64 u, v;
}edge[100000*4+10];
int main()
{
	__int64 n;
	scanf("%I64d", &n);
	__int64 i, j, color[100000+5];
	for(i = 1; i < n; i++) scanf("%I64d%I64d", &edge[i].u, &edge[i].v);
	for(i = 1; i <= n; i++) scanf("%I64d", &color[i]);
	//printf("**\n");
	__int64 cnt[n+5], alldif = 0;
	memset(cnt, 0, sizeof(cnt));
	for(i = 1; i < n; i++)
	{
		if(color[edge[i].u] != color[edge[i].v])
		{
			alldif++;
			cnt[edge[i].u]++;
			cnt[edge[i].v]++;
		}
	}
	__int64 p = 0, pos[n+5];
	for(i = 1; i <= n; i++)
	{
		if(cnt[i] == alldif) pos[p++]=i;
		//printf("%d\n", cnt[i]);
	}
	if(!p) printf("NO\n");
	else
	{
		printf("YES\n");
		printf("%I64d\n", pos[0]);
	}
	return 0;
}


#pragma comment(linker, "/STACK:64000000")
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <sstream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define y1 stupid_cmath
#define left stupid_left
#define right stupid_right
#define vi vector <int>
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))

const int inf = (int)1e9;
const int mod = inf + 7;
const double eps = 1e-9;
const double pi = acos(-1.0);

int n;
vector<int> g[100100];
int c[100100];
int down[100100];
int up[100100];

void print(int ans) {
    if (ans == -1) cout << "NO" << endl;
    else {
        cout << "YES" << endl;
        cout << ans << endl;
    }
    exit(0);
}

void dfs(int v, int par) {
    down[v] = 1;
    set<int> tmp;
    forit (it, g[v]) {
        int to = *it;
        if (to == par) continue;
        dfs(to, v);
        if (!down[to]) down[v] = 0;
        else tmp.insert(c[to]);
    }
    if (down[v] == 0) return;
    if (tmp.size() == 0) down[v] = 1;
    else if (tmp.size() > 1) down[v] = 0;
    else down[v] = (*tmp.begin() == c[v]);
}

void dfs2(int v, int par) {
    int cnt = 0;
    forit (it, g[v]) {
        int to = *it;
        if (to == par) continue;
        up[to] = 1;
        cnt++;
    }
    if (up[v] == 0) {
        forit (it, g[v]) {
            int to = *it;
            if (to == par) continue;
            up[to] = 0;
        }
    } else {
        vector<int> pr(cnt, 1);
        vector<int> suff(cnt, 1);
        int cc = c[v];
        int cur = 0;
        forit (it, g[v]) {
            int to = *it;
            if (to == par) continue;
            if (cc != c[to]) cc = -1;
            if (cc == -1) pr[cur++] = 0;
            if (down[to] == 0) cc = -1;
        }
        cc = c[v];
        cur = cnt - 1;
        for (int i = sz(g[v]) - 1; i >= 0; i--) {
            int to = g[v][i];
            if (to == par) continue;
            if (cc != c[to]) cc = -1;
            if (cc == -1) suff[cur--] = 0;
            if (down[to] == 0) cc = -1;
        }
        cur = 0;
        forit (it, g[v]) {
            int to = *it;
            if (to == par) continue;
            if (pr[cur] && suff[cur]) up[to] = 1;
            else up[to] = 0;
            cur++;
        }
    }
    forit (it, g[v]) {
        int to = *it;
        if (to == par) continue;
        dfs2(to, v);
    }
}

void find_ans(int v, int par) {
    int ans = 1;
    if (par != -1) ans &= up[par];
    forit (it, g[v]) {
        int to = *it;
        if (to != par) ans &= down[to];
    }
    if (ans) print(v + 1);
    forit (it, g[v]) {
        int to = *it;
        if (to != par) find_ans(to, v);
    }
}

int main(){

    scanf("%d", &n);
    for (int i = 1, x, y; i < n; i++) {
        scanf("%d%d", &x, &y);
        x--; y--;
        g[x].pb(y);
        g[y].pb(x);
    }
    for (int i = 0; i < n; i++) {
        scanf("%d", c + i);
    }

    dfs(0, -1);
    up[0] = 1;
    dfs2(0, -1);

    find_ans(0, -1);

    print(-1);

    return 0;
}


#pragma comment(linker, "/STACK:64000000")
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <sstream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define y1 stupid_cmath
#define left stupid_left
#define right stupid_right
#define vi vector <int>
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))

const int inf = (int)1e9;
const int mod = inf + 7;
const double eps = 1e-9;
const double pi = acos(-1.0);

int n;
vector<int> g[100100];
int c[100100];
int down[100100];
int up[100100];

void print(int ans) {
    if (ans == -1) cout << "NO" << endl;
    else {
        cout << "YES" << endl;
        cout << ans << endl;
    }
    exit(0);
}

void dfs(int v, int par) {
    down[v] = 1;
    set<int> tmp;
    forit (it, g[v]) {
        int to = *it;
        if (to == par) continue;
        dfs(to, v);
        if (!down[to]) down[v] = 0;
        else tmp.insert(c[to]);
    }
    if (down[v] == 0) return;
    if (tmp.size() == 0) down[v] = 1;
    else if (tmp.size() > 1) down[v] = 0;
    else down[v] = (*tmp.begin() == c[v]);
}

void dfs2(int v, int par) {
    forit (it, g[v]) {
        int to = *it;
        if (to == par) continue;
        up[to] = 1;
    }
    int has_false = 0;
    set<int> tmp;
    tmp.insert(c[v]);
    if (up[v] == 0) has_false = 1;
    forit (it, g[v]) {
        int to = *it;
        if (to == par) continue;
        if (has_false) up[to] = 0;
        else {
            if (tmp.size() > 1) up[to] = 0;
            else if (*tmp.begin() != c[to]) up[to] = 0;
        }
        if (down[to] == 0) has_false = true;
        else {
            tmp.insert(c[to]);
        }
    }
    tmp.clear();
    tmp.insert(c[v]);
    has_false = 0;
    if (up[v] == 0) has_false = 1;
    reverse(all(g[v]));
    forit (it, g[v]) {
        int to = *it;
        if (to == par) continue;
        if (has_false) up[to] = 0;
        else {
            if (tmp.size() > 1) up[to] = 0;
            else if (*tmp.begin() != c[to]) up[to] = 0;
        }
        if (down[to] == 0) has_false = true;
        else {
            tmp.insert(c[to]);
        }
    }
    forit (it, g[v]) {
        int to = *it;
        if (to == par) continue;
        dfs2(to, v);
    }
}

void find_ans(int v, int par) {
    int ans = 1;
    if (par != -1) ans &= up[par];
    forit (it, g[v]) {
        int to = *it;
        if (to != par) ans &= down[to];
    }
    if (ans) print(v + 1);
    forit (it, g[v]) {
        int to = *it;
        if (to != par) find_ans(to, v);
    }
}

int main(){

    scanf("%d", &n);
    for (int i = 1, x, y; i < n; i++) {
        scanf("%d%d", &x, &y);
        x--; y--;
        g[x].pb(y);
        g[y].pb(x);
    }
    for (int i = 0; i < n; i++) {
        scanf("%d", c + i);
    }

    dfs(0, -1);
    up[0] = 1;
    dfs2(0, -1);

    find_ans(0, -1);

    print(-1);

    return 0;
}


#pragma comment(linker, "/STACK:64000000")
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <sstream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define y1 stupid_cmath
#define left stupid_left
#define right stupid_right
#define vi vector <int>
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))

const int inf = (int)1e9;
const int mod = inf + 7;
const double eps = 1e-9;
const double pi = acos(-1.0);

int n;
vector<int> g[100100];
int c[100100];
int down[100100];
int up[100100];

void print(int ans) {
    if (ans == -1) cout << "NO" << endl;
    else {
        cout << "YES" << endl;
        cout << ans << endl;
    }
    exit(0);
}

bool check(int v, int par, int col) {
    if (col != c[v]) return false;
    int ans = 1;
    forit (it, g[v]) {
        int to = *it;
        if (to != par) ans &= check(to, v, col);
    }
    return ans;
}

bool check_center(int center) {
    int ans = 1;
    forit (it, g[center]) {
        int to = *it;
        ans &= check(to, center, c[to]);
    }
    return ans;
}

int main(){

    scanf("%d", &n);
    for (int i = 1, x, y; i < n; i++) {
        scanf("%d%d", &x, &y);
        x--; y--;
        g[x].pb(y);
        g[y].pb(x);
    }
    set<int> tmp;
    for (int i = 0; i < n; i++) {
        scanf("%d", c + i);
        tmp.insert(c[i]);
    }

    if (tmp.size() == 1) print(1);

    for (int i = 0; i < n; i++) {
        forit (it, g[i]) {
            int x = i;
            int y = *it;
            if (c[x] != c[y]) {
                if (check_center(x)) print(x + 1);
                if (check_center(y)) print(y + 1);
                print(-1);
            }
        }
    }

    print(-1);

    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
int c[100010];
bool visited[100010];
vector<int> v[100010];
bool dfs(int s, int color) {
    bool temp = true;
    for(int i = 0; i < v[s].size(); i++) {
        if(!visited[v[s][i]]) {
            visited[v[s][i]] = true;
            if(c[v[s][i]] != color) {
                temp = false;
                break;
            } else {
                temp = dfs(v[s][i], color);
                if(!temp) {
                    break;
                }
            }
        }
    }
    return temp;
}
int main()
{
    int n, i, j, k;
    scanf("%d", &n);
    for(i = 1; i < n; i++) {
        scanf("%d %d", &j, &k);
        v[j].push_back(k);
        v[k].push_back(j);
    }
    for(i = 1; i <= n; i++) {
        scanf("%d", &c[i]);
    }
    bool flag = false;
    for(i = 1; i <= n; i++) {
        for(j = 1; j <= n; j++) {
            visited[j] = false;
        }
        visited[i] = true;
        bool temp;
        for(j = 0; j < v[i].size(); j++) {
            if(!visited[v[i][j]]) {
                temp = dfs(v[i][j], c[v[i][j]]);
                if(!temp) {
                    break;
                }
            }
        }
        if(temp) {
            break;
        }
    }
    if(i > n) {
        printf("NO\n");
    } else {
        printf("YES\n%d\n", i);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int vis[200005],col[200005],vis2[200005];
int possiblePoint;
vector <int> tree[200005];
int dfs(int node,int colour)
{
    vis[node]=1;
    if(col[node]!=colour)
    {
        if(possiblePoint!=-1)
            return 0;
        else
        {
            possiblePoint = node;
            return 1;
        }
    }
    for(int i= 0; i<tree[node].size(); i++)
    {
        if(vis[tree[node][i]] == 0)
        {
          /*  if(col[tree[node][i]]!=colour)
            {
                if(possiblePoint!=-1)
                    return 0;
                else
                {
                    possiblePoint = tree[node][i];
                    return 1;
                }
            }
            else
            {*/
                if(dfs(tree[node][i],colour) == 0)
                    return 0;
          //  }
        }
    }
    return 1;
}
int dfs2(int node,int colour)
{
    vis2[node]=1;
    for(int i = 0; i<tree[node].size(); i++)
    {
        if(vis2[tree[node][i]]== 0)
        {
         //   printf("node:%d tree[node][i]:%d col[tree[node][i]]:%d colour:%d\n",node,tree[node][i],col[tree[node][i]],colour);
            if(col[tree[node][i]]!=colour)
            {
                return 0;
            }
            else
            {
                if(dfs2(tree[node][i],colour) == 0)
                    return 0;
            }
        }
    }
    return 1;
}
int check(int p)
{
    for(int i = 0; i<tree[p].size(); i++)
    {
       // printf("tree[p][i]=%d vis2[tree[p][i]]:%d\n",tree[p][i],vis2[tree[p][i]]);
        if(vis2[tree[p][i]] == 0)
        {
          //  printf("entering tree[p][i]=%d col[p][i]=%d\n",tree[p][i],col[tree[p][i]]);
            if(dfs2(tree[p][i],col[tree[p][i]]) == 0)
            {
                return 0;
            }
        }
    }
    return 1;
}
int main()
{
    int n,u,v,t,i;
    int in[200005];
    int maxi=-1;
    int pos = -1;
    memset(in,0,sizeof(int));
    scanf("%d",&n);
    for(i = 0; i<n-1; i++)
    {
        scanf("%d %d",&u,&v);
        tree[u].push_back(v);
        tree[v].push_back(u);
        in[u]++;
        in[v]++;
        if(in[u]>in[v] && in[u]>maxi)
        {
            maxi = in[u];
            pos = u;
        }
        if(in[v]>in[u] && in[v]>maxi)
        {
            maxi = in[v];
            pos = v;
        }
    }
    for(i = 1; i<=n; i++)
        scanf("%d",&col[i]);
    memset(vis,0,sizeof(int));
    possiblePoint = -1;
    t = dfs(pos,col[pos]);
  //  printf("pos:%d t:%d possiblePoint:%d\n",pos,t,possiblePoint);

    if(t == 0)
    {
        memset(vis2,0,sizeof(int));
        vis2[pos]=1;
        t = check(pos);
      //  printf("t:%d\n",t);
        if(t == 1)
            printf("YES\n%d",pos);
        else
            printf("NO");
    }
    else
    {
        if(possiblePoint!=-1)
        {
            memset(vis2,0,sizeof(int));
            vis2[possiblePoint] = 1;
            t = check(possiblePoint);
          //  printf("t:%d\n",t);
            if(t == 1)
                printf("YES\n%d\n",possiblePoint);
            else
                printf("NO\n");

        }
        else
        {
            printf("YES\n%d\n",pos);
        }
    }
/*    memset(diff,0,sizeof(int));
    num = 0;
    for(i = 0; i<n; i++)
    {
        scanf("%d",&col[i]);
        if(diff[col[i]] == 0)
        {
            vec.push_back(col[i]);
        }
        diff[col[i]]++;
    }
    num = vec.size();
    if(num>3)
        printf("NO");
    else if(num == 1)
        printf("YES\n1");
    else if(num == 3)
    {
        test = 0;
        for(i = 0; i<num; i++)
        {
            if(diff[col[i]] == 1)
            {
                int p = find(col,col+n,col[i])-col;
                if(check(p) == 1)
                {
                    printf("YES\n%d",p);
                    test = 1;
                    break;
                }
            }
        }
        if(test == 0)
            printf("NO");
    }
    else
    {

    }*/
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int vis[200005],col[200005],vis2[200005];
int possiblePoint;
vector <int> tree[200005];
int dfs(int node,int colour)
{
    vis[node]=1;
    if(col[node]!=colour)
    {
        if(possiblePoint!=-1)
            return 0;
        else
        {
            possiblePoint = node;
            return 1;
        }
    }
    for(int i= 0; i<tree[node].size(); i++)
    {
        if(vis[tree[node][i]] == 0)
        {
          /*  if(col[tree[node][i]]!=colour)
            {
                if(possiblePoint!=-1)
                    return 0;
                else
                {
                    possiblePoint = tree[node][i];
                    return 1;
                }
            }
            else
            {*/
                if(dfs(tree[node][i],colour) == 0)
                    return 0;
          //  }
        }
    }
    return 1;
}
int dfs2(int node,int colour)
{
    vis2[node]=1;
    for(int i = 0; i<tree[node].size(); i++)
    {
        if(vis2[tree[node][i]]== 0)
        {
         //   printf("node:%d tree[node][i]:%d col[tree[node][i]]:%d colour:%d\n",node,tree[node][i],col[tree[node][i]],colour);
            if(col[tree[node][i]]!=colour)
            {
                return 0;
            }
            else
            {
                if(dfs2(tree[node][i],colour) == 0)
                    return 0;
            }
        }
    }
    return 1;
}
int check(int p)
{
    for(int i = 0; i<tree[p].size(); i++)
    {
       // printf("tree[p][i]=%d vis2[tree[p][i]]:%d\n",tree[p][i],vis2[tree[p][i]]);
        if(vis2[tree[p][i]] == 0)
        {
          //  printf("entering tree[p][i]=%d col[p][i]=%d\n",tree[p][i],col[tree[p][i]]);
            if(dfs2(tree[p][i],col[tree[p][i]]) == 0)
            {
                return 0;
            }
        }
    }
    return 1;
}
int main()
{
    int n,u,v,t,i;
    int in[200005];
    int maxi=-1;
    int pos = -1;
    memset(in,0,sizeof(int));
    scanf("%d",&n);
    for(i = 0; i<n-1; i++)
    {
        scanf("%d %d",&u,&v);
        tree[u].push_back(v);
        tree[v].push_back(u);
        in[u]++;
        in[v]++;
        if(in[u]>=in[v] && in[u]>maxi)
        {
            maxi = in[u];
            pos = u;
        }
        if(in[v]>in[u] && in[v]>maxi)
        {
            maxi = in[v];
            pos = v;
        }
    }
    for(i = 1; i<=n; i++)
        scanf("%d",&col[i]);
    memset(vis,0,sizeof(int));
    possiblePoint = -1;
    t = dfs(pos,col[pos]);
  //  printf("pos:%d t:%d possiblePoint:%d\n",pos,t,possiblePoint);

    if(t == 0)
    {
        memset(vis2,0,sizeof(int));
        vis2[pos]=1;
        t = check(pos);
      //  printf("t:%d\n",t);
        if(t == 1)
            printf("YES\n%d",pos);
        else
            printf("NO");
    }
    else
    {
        if(possiblePoint!=-1)
        {
            memset(vis2,0,sizeof(int));
            vis2[possiblePoint] = 1;
            t = check(possiblePoint);
          //  printf("t:%d\n",t);
            if(t == 1)
                printf("YES\n%d\n",possiblePoint);
            else
                printf("NO\n");

        }
        else
        {
            printf("YES\n%d\n",pos);
        }
    }
/*    memset(diff,0,sizeof(int));
    num = 0;
    for(i = 0; i<n; i++)
    {
        scanf("%d",&col[i]);
        if(diff[col[i]] == 0)
        {
            vec.push_back(col[i]);
        }
        diff[col[i]]++;
    }
    num = vec.size();
    if(num>3)
        printf("NO");
    else if(num == 1)
        printf("YES\n1");
    else if(num == 3)
    {
        test = 0;
        for(i = 0; i<num; i++)
        {
            if(diff[col[i]] == 1)
            {
                int p = find(col,col+n,col[i])-col;
                if(check(p) == 1)
                {
                    printf("YES\n%d",p);
                    test = 1;
                    break;
                }
            }
        }
        if(test == 0)
            printf("NO");
    }
    else
    {

    }*/
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int vis[200005],col[200005],vis2[200005];
int possiblePoint;
vector <int> tree[200005];
int dfs(int node,int colour)
{
    vis[node]=1;
    for(int i= 0; i<tree[node].size(); i++)
    {
        if(vis[tree[node][i]] == 0)
        {
            if(col[tree[node][i]]!=colour)
            {
                if(possiblePoint!=-1)
                    return 0;
                else
                    possiblePoint = tree[node][i];
            }
            else
            {
                if(dfs(tree[node][i],colour) == 0)
                    return 0;
            }
        }
    }
    return 1;
}
int dfs2(int node,int colour)
{
    vis2[node]=1;
    for(int i = 0; i<tree[node].size(); i++)
    {
        if(vis2[tree[node][i]]== 0)
        {
         //   printf("node:%d tree[node][i]:%d col[tree[node][i]]:%d colour:%d\n",node,tree[node][i],col[tree[node][i]],colour);
            if(col[tree[node][i]]!=colour)
            {
                return 0;
            }
            else
            {
                if(dfs2(tree[node][i],colour) == 0)
                    return 0;
            }
        }
    }
    return 1;
}
int check(int p)
{
    for(int i = 0; i<tree[p].size(); i++)
    {
       // printf("tree[p][i]=%d vis2[tree[p][i]]:%d\n",tree[p][i],vis2[tree[p][i]]);
        if(vis2[tree[p][i]] == 0)
        {
          //  printf("entering tree[p][i]=%d col[p][i]=%d\n",tree[p][i],col[tree[p][i]]);
            if(dfs2(tree[p][i],col[tree[p][i]]) == 0)
            {
                return 0;
            }
        }
    }
    return 1;
}
int main()
{
    int n,u,v,t,i;
    scanf("%d",&n);
    for(i = 0; i<n-1; i++)
    {
        scanf("%d %d",&u,&v);
        tree[u].push_back(v);
        tree[v].push_back(u);
    }
    for(i = 1; i<=n; i++)
        scanf("%d",&col[i]);
    memset(vis,0,sizeof(int));
    possiblePoint = -1;
    t = dfs(1,col[1]);
  //  printf("t:%d possiblePoint:%d\n",t,possiblePoint);

    if(t == 0)
    {
        memset(vis2,0,sizeof(int));
        vis2[1]=1;
        t = check(1);
      //  printf("t:%d\n",t);
        if(t == 1)
            printf("YES\n1");
        else
            printf("NO");
    }
    else
    {
        if(possiblePoint!=-1)
        {
            memset(vis2,0,sizeof(int));
            vis2[possiblePoint] = 1;
            t = check(possiblePoint);
          //  printf("t:%d\n",t);
            if(t == 1)
                printf("YES\n%d\n",possiblePoint);
            else
                printf("NO\n");

        }
        else
        {
            printf("YES\n1\n");
        }
    }
/*    memset(diff,0,sizeof(int));
    num = 0;
    for(i = 0; i<n; i++)
    {
        scanf("%d",&col[i]);
        if(diff[col[i]] == 0)
        {
            vec.push_back(col[i]);
        }
        diff[col[i]]++;
    }
    num = vec.size();
    if(num>3)
        printf("NO");
    else if(num == 1)
        printf("YES\n1");
    else if(num == 3)
    {
        test = 0;
        for(i = 0; i<num; i++)
        {
            if(diff[col[i]] == 1)
            {
                int p = find(col,col+n,col[i])-col;
                if(check(p) == 1)
                {
                    printf("YES\n%d",p);
                    test = 1;
                    break;
                }
            }
        }
        if(test == 0)
            printf("NO");
    }
    else
    {

    }*/
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
int vis[200005],col[200005];
int possiblePoint;
vector <int> tree[200005];
int dfs(int node,int colour)
{
    vis[node]=1;
    for(int i= 0; i<tree[node].size(); i++)
    {
        if(vis[tree[node][i]] == 0)
        {
            if(col[tree[node][i]]!=colour)
            {
                if(possiblePoint!=-1)
                    return 0;
                else
                    possiblePoint = tree[node][i];
            }
            else
            {
                if(dfs(tree[node][i],colour) == 0)
                    return 0;
            }
        }
    }
    return 1;
}
int dfs2(int node,int colour)
{
    vis[node]=1;
    for(int i = 0; i<tree[node].size(); i++)
    {
        if(vis[tree[node][i]]== 0)
        {
            if(col[tree[node][i]]!=colour)
            {
                return 0;
            }
            else
            {
                if(dfs2(tree[node][i],colour) == 0)
                    return 0;
            }
        }
    }
    return 1;
}
int check(int p)
{
    for(int i = 0; i<tree[p].size(); i++)
    {
     //   printf("tree[p][i]=%d\n",tree[p][i]);
        if(vis[tree[p][i]] == 0)
        {
          //  printf("entering tree[p][i]=%d col[p][i]=%d\n",tree[p][i],col[tree[p][i]]);
            if(dfs2(tree[p][i],col[tree[p][i]]) == 0)
            {
                return 0;
            }
        }
    }
    return 1;
}
int main()
{
    int n,u,v,t,i;
    scanf("%d",&n);
    for(i = 0; i<n-1; i++)
    {
        scanf("%d %d",&u,&v);
        tree[u].push_back(v);
        tree[v].push_back(u);
    }
    for(i = 1; i<=n; i++)
        scanf("%d",&col[i]);
    memset(vis,0,sizeof(int));
    possiblePoint = -1;
    t = dfs(1,col[1]);
  //  printf("t:%d possiblePoint:%d\n",t,possiblePoint);
    vis[possiblePoint] = 1;
    if(t == 0)
    {
        t = check(1);
      //  printf("t:%d\n",t);
        if(t == 1)
            printf("YES\n1");
        else
            printf("NO");
    }
    else
    {
        if(possiblePoint!=-1)
        {
            t = check(possiblePoint);
          //  printf("t:%d\n",t);
            if(t == 1)
                printf("YES\n%d",possiblePoint);
            else
                printf("NO");

        }
        else
        {
            printf("YES\n%d",1);
        }
    }
/*    memset(diff,0,sizeof(int));
    num = 0;
    for(i = 0; i<n; i++)
    {
        scanf("%d",&col[i]);
        if(diff[col[i]] == 0)
        {
            vec.push_back(col[i]);
        }
        diff[col[i]]++;
    }
    num = vec.size();
    if(num>3)
        printf("NO");
    else if(num == 1)
        printf("YES\n1");
    else if(num == 3)
    {
        test = 0;
        for(i = 0; i<num; i++)
        {
            if(diff[col[i]] == 1)
            {
                int p = find(col,col+n,col[i])-col;
                if(check(p) == 1)
                {
                    printf("YES\n%d",p);
                    test = 1;
                    break;
                }
            }
        }
        if(test == 0)
            printf("NO");
    }
    else
    {

    }*/
    return 0;
}


#include <bits/stdc++.h>
#define s second
#define ll long long
#define ld long double
#define f first
#define pb push_back
#define files1 freopen("input.txt","r",stdin)
#define files2 freopen("output.txt","w",stdout)
#define files files1;files2
#define mp make_pair
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define ii input<int>()
#define fill(x) memset((x), 0, sizeof((x)))
#define ill input<ll>()
using namespace std;

void bad(string mes = "impossible"){cout << mes;exit(0);}

template<typename T>
string bin(T x, int st = 2){
    string ans = "";
    while (x > 0){
        ans += char('0' + x % st);
        x /= st;
    }
    reverse(ans.begin(), ans.end());
    return ans.empty() ? "0" : ans;
}

template<typename T>
T dcm(string & s)
{
    T x = 0;
    for (int i = 0; i < s.size(); i++){
        x = (x * 2) + (s[i] == '1');
    }
    return x;
}

template<typename T>
T input(){
    T ans = 0, m = 1;
    char c = ' ';
    while (c == ' ' || c == '\n')
        c = getchar();
    if (c == '-')
        m = -1, c = getchar();
    while (c >= '0' && c <= '9'){
        ans = ans * 10 + int(c - '0'), c = getchar();
    }
    return ans * m;
}

template<typename T>
T binpow(T n, T s)
{
    if (s <= 0)
        return 1LL;
    if (s % 2 == 0){
        T b = binpow(n, s / 2);
        return ( 1LL * b * b );
    } else {
        return (1LL* binpow(n, s - 1) * n );
    }
}
const int inf = 2e9;
const double eps = 1e-9;
const int maxn = 1e5 + 10, base = 1e9 + 7;
const ll llinf = 1e18;
vi a[maxn];
vector<pii> reb;
int col[maxn];
int check=-1;
int s;
void dfs(int v,int pred)
{
	if(pred!=-1&&pred!=s&&col[pred]!=col[v])
            check=-1;
	for(int i=0;i<(int)a[v].size();i++)
	{
		if(pred!=a[v][i])
			dfs(a[v][i],v);
	}
}
int main(){
	//files1;
int n=ii;
for(int i=0;i<n-1;i++)
	{
		int x=ii-1,y=ii-1;
		a[x].pb(y);
		a[y].pb(x);
		reb.pb(mp(x,y));
	}
	for(int i=0;i<n;i++)
	{
		col[i]=ii;
	}
	int x=inf,y=inf;
	for(int i=0;i<n-1;i++)
	{
		if(col[reb[i].f]!=col[reb[i].s])
		{
			x=reb[i].f;
			y=reb[i].s;
//cout<< x<<' '<<y;
			break;
		}
	}
	if(x==inf)
	{
		cout<<"YES"<<endl<<'1';
		return 0;
	}
check=x;
s=x;
	dfs(x,-1);
if(check==-1){
	check=y;
s=y;
	dfs(y,-1);
}
	if(check==-1)
		cout<<"NO";
	else
		cout<<"YES"<<endl<<check+1;
return 0;

}


#include <bits/stdc++.h>
#define s second
#define ll long long
#define ld long double
#define f first
#define pb push_back
#define files1 freopen("input.txt","r",stdin)
#define files2 freopen("output.txt","w",stdout)
#define files files1;files2
#define mp make_pair
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define ii input<int>()
#define fill(x) memset((x), 0, sizeof((x)))
#define ill input<ll>()
using namespace std;

void bad(string mes = "impossible"){cout << mes;exit(0);}

template<typename T>
string bin(T x, int st = 2){
    string ans = "";
    while (x > 0){
        ans += char('0' + x % st);
        x /= st;
    }
    reverse(ans.begin(), ans.end());
    return ans.empty() ? "0" : ans;
}

template<typename T>
T dcm(string & s)
{
    T x = 0;
    for (int i = 0; i < s.size(); i++){
        x = (x * 2) + (s[i] == '1');
    }
    return x;
}

template<typename T>
T input(){
    T ans = 0, m = 1;
    char c = ' ';
    while (c == ' ' || c == '\n')
        c = getchar();
    if (c == '-')
        m = -1, c = getchar();
    while (c >= '0' && c <= '9'){
        ans = ans * 10 + int(c - '0'), c = getchar();
    }
    return ans * m;
}

template<typename T>
T binpow(T n, T s)
{
    if (s <= 0)
        return 1LL;
    if (s % 2 == 0){
        T b = binpow(n, s / 2);
        return ( 1LL * b * b );
    } else {
        return (1LL* binpow(n, s - 1) * n );
    }
}
const int inf = 2e9;
const double eps = 1e-9;
const int maxn = 1e5 + 10, base = 1e9 + 7;
const ll llinf = 1e18;
vi a[maxn];
vector<pii> reb;
int col[maxn];
int check=0;
int s;
void dfs(int v,int pred)
{
	if(pred!=-1&&pred!=s&&col[pred]!=col[v])
            check=0;
	for(int i=0;i<(int)a[v].size();i++)
	{
		if(pred!=a[v][i])
			dfs(a[v][i],v);
	}
}
int main(){
	// files1;
int n=ii;
for(int i=0;i<n-1;i++)
	{
		int x=ii-1,y=ii-1;
		a[x].pb(y);
		a[y].pb(x);
		reb.pb(mp(x,y));
	}
	for(int i=0;i<n;i++)
	{
		col[i]=ii;
	}
	int x=inf,y=inf;
	for(int i=0;i<n-1;i++)
	{
		if(col[reb[i].f]!=col[reb[i].s])
		{
			x=reb[i].f;
			y=reb[i].s;
			break;
		}
	}
	if(x==inf)
	{
		cout<<"YES"<<endl<<'1';
		return 0;
	}
check=x;
s=x;
	dfs(x,-1);
if(check==0){
	check=y;
s=y;
	dfs(y,-1);
}
	if(check==0)
		cout<<"NO";
	else
		cout<<"YES"<<endl<<check+1;
return 0;

}


#include <bits/stdc++.h>
#define s second
#define ll long long
#define ld long double
#define f first
#define pb push_back
#define files1 freopen("input.txt","r",stdin)
#define files2 freopen("output.txt","w",stdout)
#define files files1;files2
#define mp make_pair
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define ii input<int>()
#define fill(x) memset((x), 0, sizeof((x)))
#define ill input<ll>()
using namespace std;

void bad(string mes = "impossible"){cout << mes;exit(0);}

template<typename T>
string bin(T x, int st = 2){
    string ans = "";
    while (x > 0){
        ans += char('0' + x % st);
        x /= st;
    }
    reverse(ans.begin(), ans.end());
    return ans.empty() ? "0" : ans;
}

template<typename T>
T dcm(string & s)
{
    T x = 0;
    for (int i = 0; i < s.size(); i++){
        x = (x * 2) + (s[i] == '1');
    }
    return x;
}

template<typename T>
T input(){
    T ans = 0, m = 1;
    char c = ' ';
    while (c == ' ' || c == '\n')
        c = getchar();
    if (c == '-')
        m = -1, c = getchar();
    while (c >= '0' && c <= '9'){
        ans = ans * 10 + int(c - '0'), c = getchar();
    }
    return ans * m;
}

template<typename T>
T binpow(T n, T s)
{
    if (s <= 0)
        return 1LL;
    if (s % 2 == 0){
        T b = binpow(n, s / 2);
        return ( 1LL * b * b );
    } else {
        return (1LL* binpow(n, s - 1) * n );
    }
}
const int inf = 2e9;
const double eps = 1e-9;
const int maxn = 1e5 + 10, base = 1e9 + 7;
const ll llinf = 1e18;
vi a[maxn];
vector<pii> reb;
int col[maxn];
int check=0;
int s;
void dfs(int v,int pred)
{
	if(pred!=-1&&pred!=s&&col[pred]!=col[v])
            check=0;
	for(int i=0;i<(int)a[v].size();i++)
	{
		if(pred!=a[v][i])
			dfs(a[v][i],v);
	}
}
int main(){
//	files1;
int n=ii;
for(int i=0;i<n-1;i++)
	{
		int x=ii-1; int y=ii-1;
		a[x].pb(y);
		a[y].pb(x);
		reb.pb(mp(x,y));
	}
	for(int i=0;i<n;i++)
	{
		col[i]=ii;
	}
	int x=inf,y=inf;
	for(int i=0;i<n-1;i++)
	{
		if(col[reb[i].f]!=col[reb[i].s])
		{
			x=reb[i].f;
			y=reb[i].s;
			break;
		}
	}
	if(x==inf)
	{
		cout<<"YES"<<endl<<'1';
		return 0;
	}
check=x;
s=x;
	dfs(x,-1);
if(check==0){
	check=y;
s=y;
	dfs(y,-1);
}
	if(check==0)
		cout<<"NO";
	else
		cout<<"YES"<<endl<<check+1;
return 0;

}


#include <bits/stdc++.h>

using namespace std;
int n,c[100050],d[100050],s,dem;
vector<int> a[100050];
void dfs(int u)
{
    d[u]=1;
    if(dem!=0) return;
    for(int i=0; i<a[u].size(); i++)
    {
        int v=a[u][i];
        if(d[v]!=0) continue;
        else
        {
            if(c[v]!=c[s]) dem++;
            dfs(v);
        }

    }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie();
    cin>>n;
    for(int i=1; i<n; i++)
    {
        int u,v;
        cin>>u>>v;
        a[u].push_back(v);
        a[v].push_back(u);
    }
    for(int i=1; i<=n; i++)
        cin>>c[i];
    for(int i=1; i<=n; i++)
    {
        dem=0;
        memset(d,0,sizeof d);
        d[i]=1;
        for(int j=0;j<a[i].size();j++)
        {
            s=a[i][j];
            if(d[s]==0) dfs(s);
        }
        if(dem==0)
        {
            cout<<"YES"<<"\n"<<i;
            exit(0);
        }
    }
    cout<<"NO";
}


#include <bits/stdc++.h>
#define ii pair<int,int>
using namespace std;
int n,c[100050],pr[100050],u[100050],v[100050],d,t;
vector<int> vt[100050];
void noi(int x,int y)
{
    pr[x]+=pr[y];
    pr[y]=x;
}
long lab(int x)
{
    if(pr[x]<0) return x;
    return pr[x]=lab(pr[x]);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie();
    cin>>n;
    for(int i=1; i<n; i++)
    {
        cin>>u[i]>>v[i];
        vt[u[i]].push_back(v[i]);
        vt[v[i]].push_back(u[i]);
    }
    for(int i=1; i<=n; i++)
    {
        cin>>c[i];
        pr[i]=-1;
    }
    for(int i=1; i<n; i++)
    {
        if(c[u[i]]==c[v[i]])
        {
            if(lab(u[i])!=lab(v[i]))
            noi(lab(u[i]),lab(v[i]));
        }
    }
    for(int i=1; i<=n; i++) if(pr[i]<0) d++;
    for(int i=1; i<=n; i++)
    {
        t=0;
        int a=lab(i);
        for(int j=0; j<vt[i].size(); j++)
        {
            int b=lab(vt[i][j]);
            if(a!=b) t++;
        }
        if(t==d-1)
        {
            cout<<"YES"<<"\n"<<i;
            exit(0);
        }
    }
    cout<<"NO";
}


#include <bits/stdc++.h>
#define ii pair<int,int>
using namespace std;
int n,c[100050],pr[100050],u[100050],v[100050],d,t;
vector<int> vt[100050];
void noi(int x,int y)
{
    pr[x]+=pr[y];
    pr[y]=x;
}
long lab(int x)
{
    if(pr[x]<0) return x;
    return pr[x]=lab(pr[x]);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie();
    cin>>n;
    for(int i=1; i<n; i++)
    {
        cin>>u[i]>>v[i];
        vt[u[i]].push_back(v[i]);
        vt[v[i]].push_back(u[i]);
    }
    for(int i=1; i<=n; i++)
    {
        cin>>c[i];
        pr[i]=-1;
    }
    for(int i=1; i<n; i++)
    {
        if(c[u[i]]==c[v[i]])
        {
            if(lab(u[i])!=lab(v[i]))
            noi(u[i],v[i]);
        }
    }
    for(int i=1; i<=n; i++) if(pr[i]<0) d++;
    for(int i=1; i<=n; i++)
    {
        t=0;
        int a=lab(i);
        for(int j=0; j<vt[i].size(); j++)
        {
            int b=lab(vt[i][j]);
            if(a!=b) t++;
        }
        if(t==d-1)
        {
            cout<<"YES"<<"\n"<<i;
            exit(0);
        }
    }
    cout<<"NO";
}


#include <cassert>
#include <cstdio>
#include <ctime>
#include <cstdlib>
#include <climits>
#include <cstddef>
#include <cctype>
#include <cmath>
#include <cstring>
#include <fstream>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <numeric>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <bitset>
#include <list>
#include <string>
#include <functional>
#include <utility>
using namespace std;
typedef long long llint;

class UF
{
public:
    UF(int n): n(n), st(n + 1), sz(n + 1, 1)
    {
    }
    int find_(int u);
    void union_(int u, int v);
private:
    int n;
    vector <int> st;
    vector <int> sz;
};

int UF::find_(int u)
{
    int r = u;
    while (st[r] != 0)
    {
        r = st[r];
    }
    int x = u, y;
    while (st[x] != 0)
    {
        y = st[x];
        st[x] = r;
        x = y;
    }
    return r;
}

void UF::union_(int u, int v)
{
    int ru = find_(u), rv = find_(v);
    if (ru == rv)
    {
        return;
    }
    if (sz[ru] >= sz[rv])
    {
        st[rv] = ru;
        sz[ru] += sz[rv];
    }
    else
    {
        st[ru] = rv;
        sz[rv] += sz[ru];
    }
}

bool can_be_root(int v, int nl, UF &uf, vector <vector <int> > const &adj)
{
    int cnt = 0;
    for (vector <int>::const_iterator jt = adj[v].begin(); jt != adj[v].end(); ++jt)
    {
        if (uf.find_(*jt) != uf.find_(v))
        {
            ++cnt;
        }
    }
    return (cnt == nl);
}

int main()
{
    std::ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector <vector <int> > adj(n + 1);
    for (int i = 0, x, y; i < n - 1; ++i)
    {
        cin >> x >> y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    vector <int> c(n + 1);
    for (int i = 1; i <= n; ++i)
    {
        cin >> c[i];
    }

    UF uf(n);
    for (int i = 1; i <= n; ++i)
    {
        for (vector <int>::const_iterator it = adj[i].begin(); it != adj[i].end(); ++it)
        {
            if (c[i] == c[*it])
            {
                uf.union_(i, *it);
            }
        }
    }

    vector <int> deg(n + 1);
    for (int i = 1; i <= n; ++i)
    {
        for (vector <int>::const_iterator it = adj[i].begin(); it != adj[i].end(); ++it)
        {
            if (uf.find_(i) == uf.find_(*it))
            {
                continue;
            }
            ++deg[uf.find_(i)];
        }
    }

    int r = count_if(deg.begin(), deg.end(), bind2nd(greater <int>(), 1));
    if (r > 1)
    {
        cout << "NO" << endl;
    }
    else if (r == 0)
    {
        cout << "YES" << endl;
        cout << 1 << endl;
    }
    else
    {
        int nl = count_if(deg.begin(), deg.end(), bind2nd(equal_to <int>(), 1));
        int u = find_if(deg.begin(), deg.end(), bind2nd(greater <int>(), 1)) - deg.begin();
        int ans = -1;
        queue <int> q;
        vector <bool> vis(n + 1);
        q.push(u);
        while (!q.empty())
        {
            int v = q.front();
            q.pop();
            vis[v] = true;
            if (can_be_root(v, nl, uf, adj))
            {
                ans = v;
                break;
            }
            for (vector <int>::const_iterator it = adj[v].begin(); it != adj[v].end(); ++it)
            {
                if (!vis[*it] && c[*it] == c[u])
                {
                    q.push(*it);
                }
            }
        }
        if (ans == -1)
        {
            cout << "NO" << endl;
        }
        else
        {
            cout << "YES" << endl << ans << endl;
        }
    }

    return 0;
}