#include "cseslib.hpp"
#include <vector>
#include <algorithm>

int main()
{
    auto nq = read_ints(2, 1, 2e5);
    auto n = nq[0];
    auto q = nq[1];

    auto x = read_ints(n, 1, 1e9);
    bool disjoint = 1;
    for (int i = 0; i < q; ++i) {
        auto ab = read_ints(2, 1, n);
        disjoint &= ab[0] + ab[1] <= n;
    }

    auto max_x = *max_element(x.begin(), x.end());

    auto sx = x;
    sort(sx.begin(), sx.end());
    bool distinct = unique(sx.begin(), sx.end()) - sx.begin() == n;

    vector<int> g;
    if (n <= 10 && q <= 10 && disjoint) g.push_back(1);
    if (n <= 10 && q <= 10) g.push_back(2);
    if (disjoint) g.push_back(3);
    if (max_x <= 2) g.push_back(4);
    if (n <= 5000 && q <= 5000 && distinct && max_x == n) g.push_back(5);
    if (n <= 5000 && q <= 5000) g.push_back(6);
    g.push_back(7);

    end_groups(g);
}
