#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; debug_print(__VA_ARGS__); } while(false)
template<typename T, typename... Ts> void debug_print(const T &t, const Ts &...ts) { cerr << t; ((cerr << ", " << ts), ...); cerr << endl; }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, const T& b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, const T& b) { if (a < b) {a = b; return true; } return false; }
template<typename T, typename... Ts> void print(const T& t, const Ts&... ts) { cout << t; ((cout << ' ' << ts), ...); cout << '\n'; }
template<typename... Ts> void input(Ts&... ts) { (cin >> ... >> ts); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

class UnionFind {
public:
    vector<int> par;
    int N;
    UnionFind(int n) {
        par.resize(n, -1);
        N = n;
    }
    int Find(int n) {
        return par[n] < 0 ? n : par[n] = Find(par[n]);
    }
    bool Union(int x, int y) {
        x = Find(x);
        y = Find(y);
        if (x == y) return false;
        if (-par[x] > -par[y]) swap(x, y);
        par[y] += par[x];
        par[x] = y;
        N--;
        return true;
    }
    bool Same(int x, int y) {
        return Find(x) == Find(y);
    }
    int size(int x) {
        return -par[Find(x)];
    }
    int size() {
        return N;
    }
};

int popcount(ll bits) {
    bits = (bits & 0x5555555555555555LL) + (bits >> 1 & 0x5555555555555555LL);
    bits = (bits & 0x3333333333333333LL) + (bits >> 2 & 0x3333333333333333LL);
    bits = (bits & 0x0f0f0f0f0f0f0f0fLL) + (bits >> 4 & 0x0f0f0f0f0f0f0f0fLL);
    bits = (bits & 0x00ff00ff00ff00ffLL) + (bits >> 8 & 0x00ff00ff00ff00ffLL);
    bits = (bits & 0x0000ffff0000ffffLL) + (bits >> 16 & 0x0000ffff0000ffffLL);
    return (bits & 0x00000000ffffffffLL) + (bits >> 32 & 0x00000000ffffffffLL);
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    input(n, m);
    vector<P> edge(m);
    vector<ll> pow2(30, 1);
    rep(i, 1, 30) {
        pow2[i] = pow2[i - 1] * 2;
    }
    rep(i, 0, m) {
        int a, b;
        input(a, b);
        a--;
        b--;
        edge[i] = P(a, b);
    }
    int bits = 1 << n;
    ll ans = 0;
    rep(bit, 0, bits) {
        vector<bool> used(n, 0);
        rep(i, 0, n) {
            if ((bit >> i) & 1) {
                used[i] = true;
            }
        }
        UnionFind uf(2 * n), uf2(n);
        bool ok = true;
        for (auto [a, b] : edge) {
            if (used[a] && used[b]) {
                ok = false;
            } else if (used[a] || used[b]) {
                continue;
            } else {
                uf.Union(a, b + n);
                uf.Union(a + n, b);
                uf2.Union(a, b);
            }
        }
        for (auto [a, b] : edge) {
            if (!used[a] && !used[b]) {
                if (uf.Same(a + n, b + n)) {
                    ok = false;
                    break;
                }
            }
        }
        if (ok) {
            ans += pow2[uf2.size() - popcount(bit)];
        }
    }
    print(ans);
    return 0;
}

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    int n;
    cin >> n;
    vector< int > p(n+1);
    vector< vector< int > > p2c(n+1, vector< int >());
    for(int i = 2; i <= n; i++){
        cin >> p[i];
        p2c[p[i]].push_back(i);
    }

    vector< int > dp(n+1, -1), dpz(n+1, -1);

    auto f = [&](auto f, int v)->void{
        if(p2c[v].size() == 0){
            dp[v] = 1;
            dpz[v] = 1;
            return;
        }
        dp[v] = 1;
        vector< int > vp;
        int pn = 0;
        for(int w: p2c[v]){
            f(f, w);
            if(dp[w] < 0 && dpz[w] == 0){
                dp[v] += dp[w];
            }else if(dpz[w] == 0){
                pn += dp[w];
            }else{
                vp.push_back(dp[w]);
            }
        }
        sort(vp.begin(), vp.end());
        int vs = vp.size();
        for(int i = 0; i < vs; i++) dp[v] += (i%2 == 0 ? vp[i] : -vp[i]);
        dp[v] += (vs%2 == 0 ? pn : -pn);
        dpz[v] = (1-vs%2);
    };
    f(f, 1);
    cout << (n+dp[1])/2 << endl;
}
