using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AbbyC1
{
    public static void Main(String[] args)
    {
        string inp = Console.ReadLine();
        int n = int.Parse(inp);
        inp = Console.ReadLine();
        int k = int.Parse(inp);

        int[,] like = new int[n, n];

        for (int i = 0; i < k; i++)
        {
            inp = Console.ReadLine();
            string[] spl = inp.Split(' ');
            int a = int.Parse(spl[0]) - 1;
            int b = int.Parse(spl[1]) - 1;
            like[a, b] = 1;
            like[b, a] = 1;
        }
        inp = Console.ReadLine();
        int m = int.Parse(inp);

        for (int i = 0; i < m; i++)
        {
            inp = Console.ReadLine();
            string[] spl = inp.Split(' ');
            int a = int.Parse(spl[0]) - 1;
            int b = int.Parse(spl[1]) - 1;
            like[a, b] = -1;
            like[b, a] = -1;
        }
        bool[] visited = new bool[n];
        int res = 0;
        for (int i = 0; i < n; i++)
        {
            if (visited[i]) continue;

            res = Math.Max(res, markConnected(i, like, visited));
        }
        Console.WriteLine(res);
    }

    private static int markConnected(int from, int[,] like, bool[] visited)
    {
        visited[from] = true;
        int res = 0;
        bool fail = false;

        List<int> visited_here = new List<int>();
        Queue<int> q = new Queue<int>();
        q.Enqueue(from);
        visited_here.Add(from);

        while (q.Count > 0)
        {
            int cur = q.Dequeue();
            for (int i = 0; i < visited.Length; i++)
            {
                if (visited[i]) continue;
                if (like[cur, i] > 0)
                {
                    q.Enqueue(i);
                    visited_here.Add(i);
                    visited[i] = true;
                }
            }
        }

        foreach (int a in visited_here)
            foreach (int b in visited_here)
                if (a != b && like[a, b] < 0) fail = true;

        if (fail) return 0;
        return visited_here.Count;
    }

}

using System;
using System.IO;
using System.Text;

namespace Party
{
    internal class Program
    {
        private static readonly StreamReader reader = new StreamReader(Console.OpenStandardInput(1024*10), Encoding.ASCII, false, 1024*10);
        private static readonly StreamWriter writer = new StreamWriter(Console.OpenStandardOutput(1024*10), Encoding.ASCII, 1024*10);

        private static int[] p;
        private static int[] size;

        private static void Main(string[] args)
        {
            writer.WriteLine(Solve(args));
            writer.Flush();
        }

        private static int Solve(string[] args)
        {
            int n = Next();

            p = new int[n];

            size = new int[n];
            for (int i = 0; i < n; i++)
            {
                p[i] = i;
                size[i] = 1;
            }

            int k = Next();
            for (int i = 0; i < k; i++)
            {
                int u = Next() - 1;
                int v = Next() - 1;
                int pu = GP(u);
                int pv = GP(v);
                if (pu != pv)
                {
                    p[pu] = pv;
                    size[pv] += size[pu];
                }
            }

            var f = new bool[n];
            int m = Next();
            for (int i = 0; i < m; i++)
            {
                int u = Next() - 1;
                int v = Next() - 1;
                int pu = GP(u);
                int pv = GP(v);
                if (pu == pv)
                {
                    f[pu] = true;
                }
            }

            int max = 0;
            for (int i = 0; i < n; i++)
            {
                if (p[i] == i && !f[i] && size[i] > max)
                    max = size[i];
            }

            return max;
        }

        private static int GP(int i)
        {
            if (i == p[i])
                return i;
            return p[i] = GP(p[i]);
        }

        private static int Next()
        {
            int c;
            int res = 0;
            do
            {
                c = reader.Read();
                if (c == -1)
                    return res;
            } while (c < '0' || c > '9');
            res = c - '0';
            while (true)
            {
                c = reader.Read();
                if (c < '0' || c > '9')
                    return res;
                res *= 10;
                res += c - '0';
            }
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Codeforces._20120421
{
    public class C
    {
        public static void Main()
        {
            int n = int.Parse(Console.ReadLine());

            List<List<int>> friends = new List<List<int>>();
            for (int i = 0; i < n; ++i)
                friends.Add(new List<int>());

            int k = int.Parse(Console.ReadLine());
            for (int i = 0; i < k; ++i)
            {
                List<int> ab = Console.ReadLine().Split(' ').Select(t => int.Parse(t)).ToList();
                int a = ab[0] - 1;
                int b = ab[1] - 1;

                friends[a].Add(b);
                friends[b].Add(a);
            }

            List<List<int>> enemies = new List<List<int>>();
            for (int i = 0; i < n; ++i)
                enemies.Add(new List<int>());

            int m = int.Parse(Console.ReadLine());
            for (int i = 0; i < m; ++i)
            {
                List<int> ab = Console.ReadLine().Split(' ').Select(t => int.Parse(t)).ToList();
                int a = ab[0] - 1;
                int b = ab[1] - 1;

                enemies[a].Add(b);
                enemies[b].Add(a);
            }

            int maxGroupSize = 0;

            for (int i = 0; i < n; ++i)
            {
                List<int> cg = new List<int>();
                cg.Add(i);

                List<int> q = new List<int>();
                q.AddRange(friends[i]);

                while (q.Count > 0)
                {
                    int cf = q[0];

                    foreach (var enemy in enemies[cf])
                    {
                        if (cg.Contains(enemy))
                        {
                            cg.Clear();
                            q.Clear();
                            break;
                        }
                    }

                    if (q.Count > 0)
                    {
                        if (cg.Contains(cf) == false)
                            cg.Add(cf);

                        foreach (var f in friends[cf])
                        {
                            if (cg.Contains(f) == false)
                                q.Add(f);
                        }

                        q.RemoveAt(0);
                    }

                }

                maxGroupSize = Math.Max(maxGroupSize, cg.Count);
            }

            Console.WriteLine(maxGroupSize);

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace c1
{
    struct couple
    {
        public int a, b;
    }

    class Program
    {
        static int Comparer(couple a, couple b)
        {
            int result = a.a - b.a;
            if (result == 0)
            {
                result = a.b - b.b;
            }
            return result;
        }

        static void Main(string[] args)
        {

            int n = Convert.ToInt32(Console.ReadLine());
            int[] used = new int[n];
            int k = Convert.ToInt32(Console.ReadLine());
            List<couple> friends = new List<couple>();
            for (int i = 0; i < k; i++)
            {
                string[] curCouple = Console.ReadLine().Split(' ');
                int a = Convert.ToInt32(curCouple[0]);
                int b = Convert.ToInt32(curCouple[1]);
                if (a > b)
                {
                    int temp = a;
                    a = b;
                    b = temp;
                }
                couple newCouple = new couple();
                newCouple.a = a-1;
                newCouple.b = b-1;
                friends.Add(newCouple);
            }
            int m = Convert.ToInt32(Console.ReadLine());
            List<couple> enemies = new List<couple>();
            for (int i = 0; i < m; i++)
            {
                string[] curCouple = Console.ReadLine().Split(' ');
                int a = Convert.ToInt32(curCouple[0]);
                int b = Convert.ToInt32(curCouple[1]);
                if (a > b)
                {
                    int temp = a;
                    a = b;
                    b = temp;
                }
                couple newCouple = new couple();
                newCouple.a = a-1;
                newCouple.b = b-1;
                enemies.Add(newCouple);
            }

            friends.Sort(Comparer);
            enemies.Sort(Comparer);

            int record = 0;

            bool onceAgain = true;
            while (onceAgain)
            {
                onceAgain = false;
                for (int i = 0; i < n; i++)
                {
                    if (used[i] == 0)
                    {
                        used[i] = 1;
                        onceAgain = true;
                        break;
                    }
                }
                bool goodGroup = true;
                foreach (couple c in friends)
                {
                    if (used[c.a] == 1) used[c.b] = 1;
                    else if (used[c.b] == 1) used[c.a] = 1;
                }
                foreach (couple c in enemies)
                {
                    if (used[c.a] == 1 && used[c.b] == 1)
                    {
                        goodGroup = false;
                    }
                }
                int cnt = 0;
                for (int j = 0; j < n; j++)
                {
                    if (used[j] == 1)
                    {
                        cnt++;
                        used[j] = -1;
                    }
                }
                if (goodGroup)
                {
                    if (record < cnt)
                    {
                        record = cnt;
                    }
                }

            }
            Console.Write(record);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Collections;

namespace CodeForces {
    struct Pair : IComparable<Pair> {
        public int First, Second, Val;
        public Pair(int f, int s, int v) {
            First = f;
            Second = s;
            Val = v;
        }
        public override string ToString() {
            return string.Format("{0} {1}", First, Second);
        }

        public int CompareTo(Pair other) {
            return Val.CompareTo(other.Val);
        }
    }

    class Cf {
        static int n, m, k, t ,ans;
        static bool[] used;
        static TextReader input;
        static void Main(string[] args) {
#if TESTS
            input = new StreamReader("input.txt");
#else
            input = Console.In;
#endif
            Solve();
#if TESTS
            Console.ReadLine();
#endif
        }

        static int[,] f;
        static int c;
        static void Solve() {
            n = ReadInt();
            used = new bool[n];
            k = ReadInt();
            f = new int[n, n];
            for (int i = 0; i < k; ++i) {
                int[] a = ReadIntArray();
                int first = --a[0];
                int second = --a[1];
                f[first, second] = 1;
                f[second, first] = 1;
            }
            m = ReadInt();
            for (int i = 0; i < m; ++i) {
                int[] a = ReadIntArray();
                int first = --a[0];
                int second = --a[1];
                f[first, second] = -1;
                f[second, first] = -1;
            }
            for (int i = 0; i < n; ++i) {
                List<int> members = new List<int>();
                members.Add(i);
                AddFriends(i, members);
                int cnt = Count(members);
                ans = Math.Max(ans, cnt);
            }
            Console.WriteLine(ans);
        }

        static int Count(List<int> fr) {
            foreach (int i in fr) {
                for (int j = 0; j < n; ++j) {
                    if (f[i, j] == -1 && fr.Contains(j)) return 0;
                }
            }
            return fr.Count;
        }

        static void AddFriends(int i, List<int> fr){
            for (int j = 0; j < n; ++j) {
                if (f[i, j] == 1 && !fr.Contains(j)) {
                    fr.Add(j);
                    AddFriends(j, fr);
                }
            }
        }

        public static int[] ReadIntArray() {
            return input.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        }

        public static int ReadInt() {
            return int.Parse(input.ReadLine());
        }
    }

    class Heap<T> : IEnumerable<T> where T : IComparable<T> {
        private List<T> heap = new List<T>();
        private int heapSize;
        private int Parent(int index) {
            return (index - 1) >> 1;
        }
        public int Count {
            get { return heap.Count; }
        }
        private int Left(int index) {
            return (index << 1) | 1;
        }
        private int Right(int index) {
            return (index << 1) + 2;
        }
        private void Max_Heapify(int i) {
            int l = Left(i);
            int r = Right(i);
            int largest = i;
            if (l < heapSize && heap[l].CompareTo(heap[i]) > 0)
                largest = l;
            if (r < heapSize && heap[r].CompareTo(heap[largest]) > 0)
                largest = r;
            if (largest != i) {
                T temp = heap[largest];
                heap[largest] = heap[i];
                heap[i] = temp;
                Max_Heapify(largest);
            }
        }
        private void BuildMaxHeap() {
            for (int i = heap.Count >> 1; i >= 0; --i)
                Max_Heapify(i);
        }

        public IEnumerator<T> GetEnumerator() {
            return heap.GetEnumerator();
        }

        public void Sort() {
            for (int i = heap.Count - 1; i > 0; --i) {
                T temp = heap[i];
                heap[i] = heap[0];
                heap[0] = temp;
                --heapSize;
                Max_Heapify(0);
            }
        }

        public T Heap_Extract_Max() {
            T max = heap[0];
            heap[0] = heap[--heapSize];
            Max_Heapify(0);
            return max;
        }

        public void Clear() {
            heap.Clear();
            heapSize = 0;
        }

        public void Insert(T item) {
            if (heapSize < heap.Count)
                heap[heapSize] = item;
            else
                heap.Add(item);
            int i = heapSize;
            while (i > 0 && heap[Parent(i)].CompareTo(heap[i]) < 0) {
                T temp = heap[i];
                heap[i] = heap[Parent(i)];
                heap[Parent(i)] = temp;
                i = Parent(i);
            }
            ++heapSize;
        }

        IEnumerator IEnumerable.GetEnumerator() {
            return ((IEnumerable)heap).GetEnumerator();
        }
    }
    public class Treap {
        private static Random rand = new Random();
        public static Treap Merge(Treap l, Treap r) {
            if (l == null) return r;
            if (r == null) return l;
            Treap res;
            if (l.y > r.y) {
                Treap newR = Merge(l.right, r);
                res = new Treap(l.x, l.y, l.left, newR);
            }
            else {
                Treap newL = Merge(l, r.left);
                res = new Treap(r.x, r.y, newL, r.right);
            }
            return res;
        }

        public void Split(int x, out Treap l, out Treap r) {
            Treap newTree = null;
            if (this.x <= x) {
                if (right == null)
                    r = null;
                else
                    right.Split(x, out newTree, out r);
                l = new Treap(this.x, y, left, newTree);
            }
            else {
                if (left == null)
                    l = null;
                else
                    left.Split(x, out l, out newTree);
                r = new Treap(this.x, y, newTree, right);
            }
        }

        public Treap Add(int x) {
            Treap l, r;
            Split(x, out l, out r);
            Treap m = new Treap(x, rand.Next());
            return Merge(Merge(l, m), r);
        }

        public Treap Remove(int x) {
            Treap l, m, r;
            Split(x - 1, out l, out r);
            r.Split(x, out m, out r);
            return Merge(l, r);
        }

        private int x, y, cost, maxTreeCost;
        private Treap left, right;
        public Treap(int x, int y, Treap l, Treap r) {
            this.x = x;
            this.y = y;
            left = l;
            right = r;
        }
        public Treap(int x, int y) : this(x, y, null, null) { }
        public void InOrder() {
            inOrder(this);
        }
        private void inOrder(Treap t) {
            if (t == null) return;
            inOrder(t.left);
            Console.WriteLine(t.x);
            inOrder(t.right);
        }
    }

    public static class Extensions {
        public static string Fill(this char c, int count) {
            char[] r = new char[count];
            for (int i = 0; i < count; ++i)
                r[i] = c;
            return new string(r);
        }

        public static int MaxIntIndex(this int[] array) {
            int max = array[0];
            int index = 0;
            for (int i = 1; i < array.Length; ++i) {
                if (array[i] > max) {
                    max = array[i];
                    index = i;
                }
            }
            return index;
        }

        public static void PrintToConsole<T>(this IEnumerable<T> arr) {
            foreach (T t in arr)
                Console.Write("{0} ", t);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace taskC
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[,] g = new int[n+1, n+1];
            int number = int.Parse(Console.ReadLine());
            int[] data;
            for (int i = 0; i < number; i++)
            {
                data = Array.ConvertAll<string, int>(Console.ReadLine().Split(), int.Parse);
                g[data[0], data[1]] = 1;
                g[data[1], data[0]] = 1;
            }

            number = int.Parse(Console.ReadLine());
            for (int i = 0; i < number; i++)
            {
                data = Array.ConvertAll<string, int>(Console.ReadLine().Split(), int.Parse);
                g[data[0], data[1]] = -1;
                g[data[1], data[0]] = -1;
            }

            /*for (int i = 1; i <= n; i++)
            {
                for (int j = 1; j <= n; j++)
                {
                    Console.Write("{0}\t", g[i, j]);
                }
                Console.WriteLine();
            }*/

            HashSet<int> already = new HashSet<int>();
            List<int> current;
            HashSet<int> currentSet;
            int max = 0;

            for (int i = 1; i <= n; i++)
            {
                if (!already.Contains(i))
                {
                    currentSet = new HashSet<int>();
                    current = new List<int>();

                    currentSet.Add(i);
                    current.Add(i);
                    already.Add(i);
                    int index = 0;
                    bool fall = false;
                    while (index < current.Count)
                    {

                        for (int j = 1; j <= n; j++)
                        {
                            if ((current[index] != j) && (g[current[index], j] == 1) && !currentSet.Contains(j))
                            {
                                current.Add(j);
                                currentSet.Add(j);
                                already.Add(j);
                            }
                            else if ((g[current[index],j]==-1) && currentSet.Contains(j))
                            {
                                fall = true;
                            }
                        }
                        if (fall) break;
                        index++;
                    }
                    if (!fall)
                    {
                        max = Math.Max(max, currentSet.Count);
                    }
                }

            }
            Console.WriteLine(max);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.IO;

class Program
{

    void solve()
    {

        int n = nextInt();
        List<int>[] likes = new List<int>[n];
        List<int>[] disLikes = new List<int>[n];

        for (int i = 0; i < n; i++)
        {
            likes[i] = new List<int>();
            disLikes[i] = new List<int>();

        }
        int k = nextInt();
        for (int i = 0; i < k; i++)
        {
            int a = nextInt() - 1;
            int b = nextInt() - 1;
            likes[a].Add(b);
            likes[b].Add(a);
        }
        int m = nextInt();
        for (int i = 0; i < m; i++)
        {
            int a = nextInt() - 1;
            int b = nextInt() - 1;
            disLikes[a].Add(b);
            disLikes[b].Add(a);
        }
        bool[] vis = new bool[n];
        bool[] curVis = new bool[n];
        int res = 0;
        for (int i = 0; i < n; i++)
            if (!vis[i])
            {

                List<int> lVis = new List<int>();
                dfs(i, vis, likes, disLikes,lVis,curVis,n);
                int num = lVis.Count;
                if (num <= res)
                    continue;
                foreach (int x in lVis)
                    curVis[x] = true;
                bool ok = true;
                foreach (int x in lVis)
                {
                    foreach (int y in disLikes[x])
                        if (curVis[y])
                            ok = false;
                }
                foreach (int x in lVis)
                    curVis[x] = false;
                if (ok)
                    res = num;
            }
        println(res);

    }

    private  void dfs(int at, bool[] vis, List<int>[] likes, List<int>[] disLikes, List<int> lVis, bool[] curVis, int n)
    {
        if (vis[at])
            return ;
        vis[at] = true;
        lVis.Add(at);
        foreach (int x in likes[at])
            dfs(x, vis, likes, disLikes, lVis, curVis, n);
    }

    private long go(int n, Dictionary<int, long> cache)
    {
        if (n == 1)
            return 1;
        if (cache.ContainsKey(n))
            return cache[n];
        long res = 0;
        for (int i = 1; i * i <= n; i++)
        {
            if (n % i == 0)
            {
                int a = i;
                int b = n / i;
                if (b > 1)
                    res = Math.Max(res, go(a, cache));
                if (a > 1)
                    res = Math.Max(res, go(b, cache));
            }
        }
        res += n;
        cache[n] = res;
        return res;
    }

    ////////////
    private void println(string Stringst)
    {
        Console.WriteLine(Stringst);
    }
    private void println(char charnum)
    {
        Console.WriteLine(charnum);
    }
    private void println(int Intnum)
    {
        Console.WriteLine(Intnum);
    }
    private void println(long Longnum)
    {
        Console.WriteLine(Longnum);
    }
    private void println(double Doublenum)
    {
        Console.WriteLine(Doublenum);
    }

    private void print(string Stringst)
    {
        Console.Write(Stringst);
    }
    private void print(int Intnum)
    {
        Console.Write(Intnum);
    }
    private void print(char charnum)
    {
        Console.Write(charnum);
    }
    private void print(long Longnum)
    {
        Console.Write(Longnum);
    }
    private void print(double Doublenum)
    {
        Console.Write(Doublenum);
    }

    string[] inputLine = new string[0];
    int inputInd = 0;
    string nextLine()
    {
        return Console.ReadLine();
    }
    void readInput()
    {
        if (inputInd != inputLine.Length)
            throw new Exception();
        inputInd = 0;
        inputLine = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        if (inputLine.Length == 0)
            readInput();

    }
    int nextInt()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return int.Parse(inputLine[inputInd++]);
    }
    long nextLong()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return long.Parse(inputLine[inputInd++]);
    }
    double nextDouble()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return double.Parse(inputLine[inputInd++]);
    }
    string nextString()
    {
        if (inputInd == inputLine.Length)
            readInput();
        return inputLine[inputInd++];
    }
    static void Main(string[] args)
    {
        new Program().solve();
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Codeforces._20120421
{
    public class C
    {
        public static void Main()
        {
            int n = int.Parse(Console.ReadLine());

            List<List<int>> friends = new List<List<int>>();
            for (int i = 0; i < n; ++i)
                friends.Add(new List<int>());

            int k = int.Parse(Console.ReadLine());
            for (int i = 0; i < k; ++i)
            {
                List<int> ab = Console.ReadLine().Split(' ').Select(t => int.Parse(t)).ToList();
                int a = ab[0] - 1;
                int b = ab[1] - 1;

                friends[a].Add(b);
                friends[b].Add(a);
            }

            List<List<int>> enemies = new List<List<int>>();
            for (int i = 0; i < n; ++i)
                enemies.Add(new List<int>());

            int m = int.Parse(Console.ReadLine());
            for (int i = 0; i < m; ++i)
            {
                List<int> ab = Console.ReadLine().Split(' ').Select(t => int.Parse(t)).ToList();
                int a = ab[0] - 1;
                int b = ab[1] - 1;

                enemies[a].Add(b);
                enemies[b].Add(a);
            }

            int maxGroupSize = 0;

            for (int i = 0; i < n; ++i)
            {
                List<int> cg = new List<int>();
                cg.Add(i);

                List<int> q = new List<int>();
                q.AddRange(friends[i]);

                while (q.Count > 0)
                {
                    int cf = q[0];

                    foreach (var enemy in enemies[cf])
                    {
                        if (cg.Contains(enemy))
                        {
                            cg.Clear();
                            q.Clear();
                            break;
                        }
                    }

                    if (q.Count > 0)
                    {
                        cg.Add(cf);
                        q.RemoveAt(0);
                    }

                }

                maxGroupSize = Math.Max(maxGroupSize, cg.Count);
            }

            Console.WriteLine(maxGroupSize);

        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace c1
{
    struct couple
    {
        public int a, b;
    }

    class Program
    {
        static int Comparer(couple a, couple b)
        {
            int result = a.a - b.a;
            if (result == 0)
            {
                result = a.b - b.b;
            }
            return result;
        }

        static void Main(string[] args)
        {

            int n = Convert.ToInt32(Console.ReadLine());
            int[] used = new int[n];
            int k = Convert.ToInt32(Console.ReadLine());
            List<couple> friends = new List<couple>();
            for (int i = 0; i < k; i++)
            {
                string[] curCouple = Console.ReadLine().Split(' ');
                int a = Convert.ToInt32(curCouple[0]);
                int b = Convert.ToInt32(curCouple[1]);
                if (a > b)
                {
                    int temp = a;
                    a = b;
                    b = temp;
                }
                couple newCouple = new couple();
                newCouple.a = a-1;
                newCouple.b = b-1;
                friends.Add(newCouple);
            }
            int m = Convert.ToInt32(Console.ReadLine());
            List<couple> enemies = new List<couple>();
            for (int i = 0; i < m; i++)
            {
                string[] curCouple = Console.ReadLine().Split(' ');
                int a = Convert.ToInt32(curCouple[0]);
                int b = Convert.ToInt32(curCouple[1]);
                if (a > b)
                {
                    int temp = a;
                    a = b;
                    b = temp;
                }
                couple newCouple = new couple();
                newCouple.a = a-1;
                newCouple.b = b-1;
                enemies.Add(newCouple);
            }

            friends.Sort(Comparer);
            enemies.Sort(Comparer);

            int record = 0;

            bool onceAgain = true;
            while (onceAgain)
            {
                onceAgain = false;
                for (int i = 0; i < n; i++)
                {
                    if (used[i] == 0)
                    {
                        used[i] = 1;
                        onceAgain=true;
                    }
                    bool goodGroup = true;
                    foreach (couple c in friends)
                    {
                        if (used[c.a] == 1) used[c.b] = 1;
                    }
                    foreach (couple c in enemies)
                    {
                        if (used[c.a]==1 && used[c.b]==1)
                        {
                            goodGroup = false;
                        }
                    }
                    int cnt = 0;
                    for (int j = 0; j < n; j++)
                    {
                        if (used[j] == 1)
                        {
                            cnt++;
                            used[j] = -1;
                        }
                    }
                    if (goodGroup)
                    {
                        if (record < cnt)
                        {
                            record = cnt;
                        }
                    }

                }
            }
            Console.Write(record);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace c1
{
    struct couple
    {
        public int a, b;
    }

    class Program
    {
        static int Comparer(couple a, couple b)
        {
            int result = a.a - b.a;
            if (result == 0)
            {
                result = a.b - b.b;
            }
            return result;
        }

        static void Main(string[] args)
        {

            int n = Convert.ToInt32(Console.ReadLine());
            int[] used = new int[n];
            int k = Convert.ToInt32(Console.ReadLine());
            List<couple> friends = new List<couple>();
            for (int i = 0; i < k; i++)
            {
                string[] curCouple = Console.ReadLine().Split(' ');
                int a = Convert.ToInt32(curCouple[0]);
                int b = Convert.ToInt32(curCouple[1]);
                if (a > b)
                {
                    int temp = a;
                    a = b;
                    b = temp;
                }
                couple newCouple = new couple();
                newCouple.a = a-1;
                newCouple.b = b-1;
                friends.Add(newCouple);
            }
            int m = Convert.ToInt32(Console.ReadLine());
            List<couple> enemies = new List<couple>();
            for (int i = 0; i < m; i++)
            {
                string[] curCouple = Console.ReadLine().Split(' ');
                int a = Convert.ToInt32(curCouple[0]);
                int b = Convert.ToInt32(curCouple[1]);
                if (a > b)
                {
                    int temp = a;
                    a = b;
                    b = temp;
                }
                couple newCouple = new couple();
                newCouple.a = a-1;
                newCouple.b = b-1;
                enemies.Add(newCouple);
            }

            friends.Sort(Comparer);
            enemies.Sort(Comparer);

            int record = 0;

            bool onceAgain = true;
            while (onceAgain)
            {
                onceAgain = false;
                for (int i = 0; i < n; i++)
                {
                    if (used[i] == 0)
                    {
                        used[i] = 1;
                        onceAgain = true;
                    }
                }
                bool goodGroup = true;
                foreach (couple c in friends)
                {
                    if (used[c.a] == 1) used[c.b] = 1;
                    else if (used[c.b] == 1) used[c.a] = 1;
                }
                foreach (couple c in enemies)
                {
                    if (used[c.a] == 1 && used[c.b] == 1)
                    {
                        goodGroup = false;
                    }
                }
                int cnt = 0;
                for (int j = 0; j < n; j++)
                {
                    if (used[j] == 1)
                    {
                        cnt++;
                        used[j] = -1;
                    }
                }
                if (goodGroup)
                {
                    if (record < cnt)
                    {
                        record = cnt;
                    }
                }

            }
            Console.Write(record);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Collections;

namespace CodeForces {
    struct Pair : IComparable<Pair> {
        public int First, Second;
        public Pair(int f, int s) {
            First = f;
            Second = s;
        }
        public override string ToString() {
            return string.Format("{0} {1}", First, Second);
        }

        public int CompareTo(Pair other) {
            return First.CompareTo(other.First);
        }
    }

    class Cf {
        static int n, m, k, t ,ans;
        static bool[] used;
        static TextReader input;
        static void Main(string[] args) {
#if TESTS
            input = new StreamReader("input.txt");
#else
            input = Console.In;
#endif
            Solve();
#if TESTS
            Console.ReadLine();
#endif
        }

        static int[,] f;
        static void Solve() {
            n = ReadInt();
            used = new bool[n];
            k = ReadInt();
            f = new int[n, n];
            for (int i = 0; i < k; ++i) {
                int[] a = ReadIntArray();
                int first = --a[0];
                int second = --a[1];
                f[first, second] = 1;
                f[second, first] = 1;
            }
            m = ReadInt();
            for (int i = 0; i < m; ++i) {
                int[] a = ReadIntArray();
                int first = --a[0];
                int second = --a[1];
                f[first, second] = -1;
                f[second, first] = -1;
            }
            for (int i = 0; i < n; ++i) {
                int cnt = 1;
                List<int> members = new List<int>();
                members.Add(i);
                for (int j = 0; j < n; ++j) {
                    if(i==j) continue;
                    if (f[i, j] == 1 & !members.Contains(j)) {
                        members.Add(j);
                        ++cnt;
                        for (int z = 0; z < n; ++z) {
                            if (f[j, z] == -1 && members.Contains(z)) {
                                members.Clear();
                                break;
                            }
                        }
                        if (members.Count == 0) {
                            cnt = 0;
                            break;
                        }
                    }
                    if (members.Count == 0) {
                        cnt = 0;
                        break;
                    }
                }
                ans = Math.Max(ans, cnt);
            }
            Console.WriteLine(ans);
        }

        public static int[] ReadIntArray() {
            return input.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        }

        public static int ReadInt() {
            return int.Parse(input.ReadLine());
        }
    }

    class Heap<T> : IEnumerable<T> where T : IComparable<T> {
        private List<T> heap = new List<T>();
        private int heapSize;
        private int Parent(int index) {
            return (index - 1) >> 1;
        }
        public int Count {
            get { return heap.Count; }
        }
        private int Left(int index) {
            return (index << 1) | 1;
        }
        private int Right(int index) {
            return (index << 1) + 2;
        }
        private void Max_Heapify(int i) {
            int l = Left(i);
            int r = Right(i);
            int largest = i;
            if (l < heapSize && heap[l].CompareTo(heap[i]) > 0)
                largest = l;
            if (r < heapSize && heap[r].CompareTo(heap[largest]) > 0)
                largest = r;
            if (largest != i) {
                T temp = heap[largest];
                heap[largest] = heap[i];
                heap[i] = temp;
                Max_Heapify(largest);
            }
        }
        private void BuildMaxHeap() {
            for (int i = heap.Count >> 1; i >= 0; --i)
                Max_Heapify(i);
        }

        public IEnumerator<T> GetEnumerator() {
            return heap.GetEnumerator();
        }

        public void Sort() {
            for (int i = heap.Count - 1; i > 0; --i) {
                T temp = heap[i];
                heap[i] = heap[0];
                heap[0] = temp;
                --heapSize;
                Max_Heapify(0);
            }
        }

        public T Heap_Extract_Max() {
            T max = heap[0];
            heap[0] = heap[--heapSize];
            Max_Heapify(0);
            return max;
        }

        public void Clear() {
            heap.Clear();
            heapSize = 0;
        }

        public void Insert(T item) {
            if (heapSize < heap.Count)
                heap[heapSize] = item;
            else
                heap.Add(item);
            int i = heapSize;
            while (i > 0 && heap[Parent(i)].CompareTo(heap[i]) < 0) {
                T temp = heap[i];
                heap[i] = heap[Parent(i)];
                heap[Parent(i)] = temp;
                i = Parent(i);
            }
            ++heapSize;
        }

        IEnumerator IEnumerable.GetEnumerator() {
            return ((IEnumerable)heap).GetEnumerator();
        }
    }
    public class Treap {
        private static Random rand = new Random();
        public static Treap Merge(Treap l, Treap r) {
            if (l == null) return r;
            if (r == null) return l;
            Treap res;
            if (l.y > r.y) {
                Treap newR = Merge(l.right, r);
                res = new Treap(l.x, l.y, l.left, newR);
            }
            else {
                Treap newL = Merge(l, r.left);
                res = new Treap(r.x, r.y, newL, r.right);
            }
            return res;
        }

        public void Split(int x, out Treap l, out Treap r) {
            Treap newTree = null;
            if (this.x <= x) {
                if (right == null)
                    r = null;
                else
                    right.Split(x, out newTree, out r);
                l = new Treap(this.x, y, left, newTree);
            }
            else {
                if (left == null)
                    l = null;
                else
                    left.Split(x, out l, out newTree);
                r = new Treap(this.x, y, newTree, right);
            }
        }

        public Treap Add(int x) {
            Treap l, r;
            Split(x, out l, out r);
            Treap m = new Treap(x, rand.Next());
            return Merge(Merge(l, m), r);
        }

        public Treap Remove(int x) {
            Treap l, m, r;
            Split(x - 1, out l, out r);
            r.Split(x, out m, out r);
            return Merge(l, r);
        }

        private int x, y, cost, maxTreeCost;
        private Treap left, right;
        public Treap(int x, int y, Treap l, Treap r) {
            this.x = x;
            this.y = y;
            left = l;
            right = r;
        }
        public Treap(int x, int y) : this(x, y, null, null) { }
        public void InOrder() {
            inOrder(this);
        }
        private void inOrder(Treap t) {
            if (t == null) return;
            inOrder(t.left);
            Console.WriteLine(t.x);
            inOrder(t.right);
        }
    }

    public static class Extensions {
        public static string Fill(this char c, int count) {
            char[] r = new char[count];
            for (int i = 0; i < count; ++i)
                r[i] = c;
            return new string(r);
        }

        public static int MaxIntIndex(this int[] array) {
            int max = array[0];
            int index = 0;
            for (int i = 1; i < array.Length; ++i) {
                if (array[i] > max) {
                    max = array[i];
                    index = i;
                }
            }
            return index;
        }

        public static void PrintToConsole<T>(this IEnumerable<T> arr) {
            foreach (T t in arr)
                Console.Write("{0} ", t);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Collections;

namespace CodeForces {
    struct Pair : IComparable<Pair> {
        public int First, Second, Val;
        public Pair(int f, int s, int v) {
            First = f;
            Second = s;
            Val = v;
        }
        public override string ToString() {
            return string.Format("{0} {1}", First, Second);
        }

        public int CompareTo(Pair other) {
            return Val.CompareTo(other.Val);
        }
    }

    class Cf {
        static int n, m, k, t ,ans;
        static bool[] used;
        static TextReader input;
        static void Main(string[] args) {
#if TESTS
            input = new StreamReader("input.txt");
#else
            input = Console.In;
#endif
            Solve();
#if TESTS
            Console.ReadLine();
#endif
        }

        static int[,] f;
        static int c;
        static void Solve() {
            n = ReadInt();
            used = new bool[n];
            k = ReadInt();
            f = new int[n, n];
            for (int i = 0; i < k; ++i) {
                int[] a = ReadIntArray();
                int first = --a[0];
                int second = --a[1];
                f[first, second] = 1;
                f[second, first] = 1;
            }
            m = ReadInt();
            for (int i = 0; i < m; ++i) {
                int[] a = ReadIntArray();
                int first = --a[0];
                int second = --a[1];
                f[first, second] = -1;
                f[second, first] = -1;
            }
            for (int i = 0; i < n; ++i) {
                List<int> members = new List<int>();
                AddFriends(i, members);
                int cnt = Count(members);
                ans = Math.Max(ans, cnt);
            }
            Console.WriteLine(ans);
        }

        static int Count(List<int> fr) {
            foreach (int i in fr) {
                for (int j = 0; j < n; ++j) {
                    if (f[i, j] == -1 && fr.Contains(j)) return 0;
                }
            }
            return fr.Count;
        }

        static void AddFriends(int i, List<int> fr){
            for (int j = 0; j < n; ++j) {
                if (f[i, j] == 1 && !fr.Contains(j)) {
                    fr.Add(j);
                    AddFriends(j, fr);
                }
            }
        }

        public static int[] ReadIntArray() {
            return input.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        }

        public static int ReadInt() {
            return int.Parse(input.ReadLine());
        }
    }

    class Heap<T> : IEnumerable<T> where T : IComparable<T> {
        private List<T> heap = new List<T>();
        private int heapSize;
        private int Parent(int index) {
            return (index - 1) >> 1;
        }
        public int Count {
            get { return heap.Count; }
        }
        private int Left(int index) {
            return (index << 1) | 1;
        }
        private int Right(int index) {
            return (index << 1) + 2;
        }
        private void Max_Heapify(int i) {
            int l = Left(i);
            int r = Right(i);
            int largest = i;
            if (l < heapSize && heap[l].CompareTo(heap[i]) > 0)
                largest = l;
            if (r < heapSize && heap[r].CompareTo(heap[largest]) > 0)
                largest = r;
            if (largest != i) {
                T temp = heap[largest];
                heap[largest] = heap[i];
                heap[i] = temp;
                Max_Heapify(largest);
            }
        }
        private void BuildMaxHeap() {
            for (int i = heap.Count >> 1; i >= 0; --i)
                Max_Heapify(i);
        }

        public IEnumerator<T> GetEnumerator() {
            return heap.GetEnumerator();
        }

        public void Sort() {
            for (int i = heap.Count - 1; i > 0; --i) {
                T temp = heap[i];
                heap[i] = heap[0];
                heap[0] = temp;
                --heapSize;
                Max_Heapify(0);
            }
        }

        public T Heap_Extract_Max() {
            T max = heap[0];
            heap[0] = heap[--heapSize];
            Max_Heapify(0);
            return max;
        }

        public void Clear() {
            heap.Clear();
            heapSize = 0;
        }

        public void Insert(T item) {
            if (heapSize < heap.Count)
                heap[heapSize] = item;
            else
                heap.Add(item);
            int i = heapSize;
            while (i > 0 && heap[Parent(i)].CompareTo(heap[i]) < 0) {
                T temp = heap[i];
                heap[i] = heap[Parent(i)];
                heap[Parent(i)] = temp;
                i = Parent(i);
            }
            ++heapSize;
        }

        IEnumerator IEnumerable.GetEnumerator() {
            return ((IEnumerable)heap).GetEnumerator();
        }
    }
    public class Treap {
        private static Random rand = new Random();
        public static Treap Merge(Treap l, Treap r) {
            if (l == null) return r;
            if (r == null) return l;
            Treap res;
            if (l.y > r.y) {
                Treap newR = Merge(l.right, r);
                res = new Treap(l.x, l.y, l.left, newR);
            }
            else {
                Treap newL = Merge(l, r.left);
                res = new Treap(r.x, r.y, newL, r.right);
            }
            return res;
        }

        public void Split(int x, out Treap l, out Treap r) {
            Treap newTree = null;
            if (this.x <= x) {
                if (right == null)
                    r = null;
                else
                    right.Split(x, out newTree, out r);
                l = new Treap(this.x, y, left, newTree);
            }
            else {
                if (left == null)
                    l = null;
                else
                    left.Split(x, out l, out newTree);
                r = new Treap(this.x, y, newTree, right);
            }
        }

        public Treap Add(int x) {
            Treap l, r;
            Split(x, out l, out r);
            Treap m = new Treap(x, rand.Next());
            return Merge(Merge(l, m), r);
        }

        public Treap Remove(int x) {
            Treap l, m, r;
            Split(x - 1, out l, out r);
            r.Split(x, out m, out r);
            return Merge(l, r);
        }

        private int x, y, cost, maxTreeCost;
        private Treap left, right;
        public Treap(int x, int y, Treap l, Treap r) {
            this.x = x;
            this.y = y;
            left = l;
            right = r;
        }
        public Treap(int x, int y) : this(x, y, null, null) { }
        public void InOrder() {
            inOrder(this);
        }
        private void inOrder(Treap t) {
            if (t == null) return;
            inOrder(t.left);
            Console.WriteLine(t.x);
            inOrder(t.right);
        }
    }

    public static class Extensions {
        public static string Fill(this char c, int count) {
            char[] r = new char[count];
            for (int i = 0; i < count; ++i)
                r[i] = c;
            return new string(r);
        }

        public static int MaxIntIndex(this int[] array) {
            int max = array[0];
            int index = 0;
            for (int i = 1; i < array.Length; ++i) {
                if (array[i] > max) {
                    max = array[i];
                    index = i;
                }
            }
            return index;
        }

        public static void PrintToConsole<T>(this IEnumerable<T> arr) {
            foreach (T t in arr)
                Console.Write("{0} ", t);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Collections;

namespace CodeForces {
    struct Pair : IComparable<Pair> {
        public int First, Second;
        public Pair(int f, int s) {
            First = f;
            Second = s;
        }
        public override string ToString() {
            return string.Format("{0} {1}", First, Second);
        }

        public int CompareTo(Pair other) {
            return First.CompareTo(other.First);
        }
    }

    class Cf {
        static int n, m, k, t ,ans;
        static bool[] used;
        static TextReader input;
        static void Main(string[] args) {
#if TESTS
            input = new StreamReader("input.txt");
#else
            input = Console.In;
#endif
            Solve();
#if TESTS
            Console.ReadLine();
#endif
        }

        static int[,] f;
        static void Solve() {
            n = ReadInt();
            used = new bool[n];
            k = ReadInt();
            f = new int[n, n];
            for (int i = 0; i < k; ++i) {
                int[] a = ReadIntArray();
                f[--a[0], --a[1]] = 1;
            }
            m = ReadInt();
            for (int i = 0; i < m; ++i) {
                int[] a = ReadIntArray();
                f[--a[0], --a[1]] = -1;
            }
            for (int i = 0; i < n; ++i) {
                used = new bool[n];
                t = 0;
                dfs(i);
                ans = Math.Max(ans, t);
            }
            Console.WriteLine(ans);
        }

        static void dfs(int v) {
            used[v] = true;
            for (int i = 0; i < n; ++i) {
                if (f[v, i] == -1) {
                    used[i] = true;
                }
                if (f[v,i]==1 && !used[i]) {
                    ++t;
                    dfs(i);
                }
            }
        }

        public static int[] ReadIntArray() {
            return input.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        }

        public static int ReadInt() {
            return int.Parse(input.ReadLine());
        }
    }

    class Heap<T> : IEnumerable<T> where T : IComparable<T> {
        private List<T> heap = new List<T>();
        private int heapSize;
        private int Parent(int index) {
            return (index - 1) >> 1;
        }
        public int Count {
            get { return heap.Count; }
        }
        private int Left(int index) {
            return (index << 1) | 1;
        }
        private int Right(int index) {
            return (index << 1) + 2;
        }
        private void Max_Heapify(int i) {
            int l = Left(i);
            int r = Right(i);
            int largest = i;
            if (l < heapSize && heap[l].CompareTo(heap[i]) > 0)
                largest = l;
            if (r < heapSize && heap[r].CompareTo(heap[largest]) > 0)
                largest = r;
            if (largest != i) {
                T temp = heap[largest];
                heap[largest] = heap[i];
                heap[i] = temp;
                Max_Heapify(largest);
            }
        }
        private void BuildMaxHeap() {
            for (int i = heap.Count >> 1; i >= 0; --i)
                Max_Heapify(i);
        }

        public IEnumerator<T> GetEnumerator() {
            return heap.GetEnumerator();
        }

        public void Sort() {
            for (int i = heap.Count - 1; i > 0; --i) {
                T temp = heap[i];
                heap[i] = heap[0];
                heap[0] = temp;
                --heapSize;
                Max_Heapify(0);
            }
        }

        public T Heap_Extract_Max() {
            T max = heap[0];
            heap[0] = heap[--heapSize];
            Max_Heapify(0);
            return max;
        }

        public void Clear() {
            heap.Clear();
            heapSize = 0;
        }

        public void Insert(T item) {
            if (heapSize < heap.Count)
                heap[heapSize] = item;
            else
                heap.Add(item);
            int i = heapSize;
            while (i > 0 && heap[Parent(i)].CompareTo(heap[i]) < 0) {
                T temp = heap[i];
                heap[i] = heap[Parent(i)];
                heap[Parent(i)] = temp;
                i = Parent(i);
            }
            ++heapSize;
        }

        IEnumerator IEnumerable.GetEnumerator() {
            return ((IEnumerable)heap).GetEnumerator();
        }
    }
    public class Treap {
        private static Random rand = new Random();
        public static Treap Merge(Treap l, Treap r) {
            if (l == null) return r;
            if (r == null) return l;
            Treap res;
            if (l.y > r.y) {
                Treap newR = Merge(l.right, r);
                res = new Treap(l.x, l.y, l.left, newR);
            }
            else {
                Treap newL = Merge(l, r.left);
                res = new Treap(r.x, r.y, newL, r.right);
            }
            return res;
        }

        public void Split(int x, out Treap l, out Treap r) {
            Treap newTree = null;
            if (this.x <= x) {
                if (right == null)
                    r = null;
                else
                    right.Split(x, out newTree, out r);
                l = new Treap(this.x, y, left, newTree);
            }
            else {
                if (left == null)
                    l = null;
                else
                    left.Split(x, out l, out newTree);
                r = new Treap(this.x, y, newTree, right);
            }
        }

        public Treap Add(int x) {
            Treap l, r;
            Split(x, out l, out r);
            Treap m = new Treap(x, rand.Next());
            return Merge(Merge(l, m), r);
        }

        public Treap Remove(int x) {
            Treap l, m, r;
            Split(x - 1, out l, out r);
            r.Split(x, out m, out r);
            return Merge(l, r);
        }

        private int x, y, cost, maxTreeCost;
        private Treap left, right;
        public Treap(int x, int y, Treap l, Treap r) {
            this.x = x;
            this.y = y;
            left = l;
            right = r;
        }
        public Treap(int x, int y) : this(x, y, null, null) { }
        public void InOrder() {
            inOrder(this);
        }
        private void inOrder(Treap t) {
            if (t == null) return;
            inOrder(t.left);
            Console.WriteLine(t.x);
            inOrder(t.right);
        }
    }

    public static class Extensions {
        public static string Fill(this char c, int count) {
            char[] r = new char[count];
            for (int i = 0; i < count; ++i)
                r[i] = c;
            return new string(r);
        }

        public static int MaxIntIndex(this int[] array) {
            int max = array[0];
            int index = 0;
            for (int i = 1; i < array.Length; ++i) {
                if (array[i] > max) {
                    max = array[i];
                    index = i;
                }
            }
            return index;
        }

        public static void PrintToConsole<T>(this IEnumerable<T> arr) {
            foreach (T t in arr)
                Console.Write("{0} ", t);
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Collections;

namespace CodeForces {
    struct Pair : IComparable<Pair> {
        public int First, Second, Val;
        public Pair(int f, int s, int v) {
            First = f;
            Second = s;
            Val = v;
        }
        public override string ToString() {
            return string.Format("{0} {1}", First, Second);
        }

        public int CompareTo(Pair other) {
            return Val.CompareTo(other.Val);
        }
    }

    class Cf {
        static int n, m, k, t ,ans;
        static bool[] used;
        static TextReader input;
        static void Main(string[] args) {
#if TESTS
            input = new StreamReader("input.txt");
#else
            input = Console.In;
#endif
            Solve();
#if TESTS
            Console.ReadLine();
#endif
        }

        static int[,] f;
        static int c;
        static void Solve() {
            n = ReadInt();
            used = new bool[n];
            k = ReadInt();
            f = new int[n, n];
            for (int i = 0; i < k; ++i) {
                int[] a = ReadIntArray();
                int first = --a[0];
                int second = --a[1];
                f[first, second] = 1;
                f[second, first] = 1;
            }
            m = ReadInt();
            for (int i = 0; i < m; ++i) {
                int[] a = ReadIntArray();
                int first = --a[0];
                int second = --a[1];
                f[first, second] = -1;
                f[second, first] = -1;
            }
            for (int i = 0; i < n; ++i) {
                List<int> members = new List<int>();
                members.Add(i);
                for (int j = 0; j < n; ++j) {
                    if(i==j) continue;
                    if (f[i, j] == 1 & !members.Contains(j)) {
                        members.Add(j);
                        for (int z = 0; z < n; ++z) {
                            if (f[j, z] == -1 && members.Contains(z)) {
                                members.Clear();
                                break;
                            }
                        }
                        if (members.Count == 0) {
                            break;
                        }
                    }
                    if (members.Count == 0) {
                        break;
                    }
                }
                ans = Math.Max(ans, members.Count);
            }
            Console.WriteLine(ans);
        }

        public static int[] ReadIntArray() {
            return input.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        }

        public static int ReadInt() {
            return int.Parse(input.ReadLine());
        }
    }

    class Heap<T> : IEnumerable<T> where T : IComparable<T> {
        private List<T> heap = new List<T>();
        private int heapSize;
        private int Parent(int index) {
            return (index - 1) >> 1;
        }
        public int Count {
            get { return heap.Count; }
        }
        private int Left(int index) {
            return (index << 1) | 1;
        }
        private int Right(int index) {
            return (index << 1) + 2;
        }
        private void Max_Heapify(int i) {
            int l = Left(i);
            int r = Right(i);
            int largest = i;
            if (l < heapSize && heap[l].CompareTo(heap[i]) > 0)
                largest = l;
            if (r < heapSize && heap[r].CompareTo(heap[largest]) > 0)
                largest = r;
            if (largest != i) {
                T temp = heap[largest];
                heap[largest] = heap[i];
                heap[i] = temp;
                Max_Heapify(largest);
            }
        }
        private void BuildMaxHeap() {
            for (int i = heap.Count >> 1; i >= 0; --i)
                Max_Heapify(i);
        }

        public IEnumerator<T> GetEnumerator() {
            return heap.GetEnumerator();
        }

        public void Sort() {
            for (int i = heap.Count - 1; i > 0; --i) {
                T temp = heap[i];
                heap[i] = heap[0];
                heap[0] = temp;
                --heapSize;
                Max_Heapify(0);
            }
        }

        public T Heap_Extract_Max() {
            T max = heap[0];
            heap[0] = heap[--heapSize];
            Max_Heapify(0);
            return max;
        }

        public void Clear() {
            heap.Clear();
            heapSize = 0;
        }

        public void Insert(T item) {
            if (heapSize < heap.Count)
                heap[heapSize] = item;
            else
                heap.Add(item);
            int i = heapSize;
            while (i > 0 && heap[Parent(i)].CompareTo(heap[i]) < 0) {
                T temp = heap[i];
                heap[i] = heap[Parent(i)];
                heap[Parent(i)] = temp;
                i = Parent(i);
            }
            ++heapSize;
        }

        IEnumerator IEnumerable.GetEnumerator() {
            return ((IEnumerable)heap).GetEnumerator();
        }
    }
    public class Treap {
        private static Random rand = new Random();
        public static Treap Merge(Treap l, Treap r) {
            if (l == null) return r;
            if (r == null) return l;
            Treap res;
            if (l.y > r.y) {
                Treap newR = Merge(l.right, r);
                res = new Treap(l.x, l.y, l.left, newR);
            }
            else {
                Treap newL = Merge(l, r.left);
                res = new Treap(r.x, r.y, newL, r.right);
            }
            return res;
        }

        public void Split(int x, out Treap l, out Treap r) {
            Treap newTree = null;
            if (this.x <= x) {
                if (right == null)
                    r = null;
                else
                    right.Split(x, out newTree, out r);
                l = new Treap(this.x, y, left, newTree);
            }
            else {
                if (left == null)
                    l = null;
                else
                    left.Split(x, out l, out newTree);
                r = new Treap(this.x, y, newTree, right);
            }
        }

        public Treap Add(int x) {
            Treap l, r;
            Split(x, out l, out r);
            Treap m = new Treap(x, rand.Next());
            return Merge(Merge(l, m), r);
        }

        public Treap Remove(int x) {
            Treap l, m, r;
            Split(x - 1, out l, out r);
            r.Split(x, out m, out r);
            return Merge(l, r);
        }

        private int x, y, cost, maxTreeCost;
        private Treap left, right;
        public Treap(int x, int y, Treap l, Treap r) {
            this.x = x;
            this.y = y;
            left = l;
            right = r;
        }
        public Treap(int x, int y) : this(x, y, null, null) { }
        public void InOrder() {
            inOrder(this);
        }
        private void inOrder(Treap t) {
            if (t == null) return;
            inOrder(t.left);
            Console.WriteLine(t.x);
            inOrder(t.right);
        }
    }

    public static class Extensions {
        public static string Fill(this char c, int count) {
            char[] r = new char[count];
            for (int i = 0; i < count; ++i)
                r[i] = c;
            return new string(r);
        }

        public static int MaxIntIndex(this int[] array) {
            int max = array[0];
            int index = 0;
            for (int i = 1; i < array.Length; ++i) {
                if (array[i] > max) {
                    max = array[i];
                    index = i;
                }
            }
            return index;
        }

        public static void PrintToConsole<T>(this IEnumerable<T> arr) {
            foreach (T t in arr)
                Console.Write("{0} ", t);
        }
    }
}