#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <map>

long long bin_pow (long long a , long long n) {
  if(n == 0){
    return 1;
  }
  if(n % 2 == 1){
    long long cnt = a * bin_pow(a , n - 1);
    return cnt;
  }
  else {
    long long cnt = bin_pow(a , n / 2);
    return cnt * cnt;
  }
}

signed main() {

  std::size_t n;
  std::cin >> n;

  long long I;
  std::cin >> I;

  std::map<int, int> mp;
  for(std::size_t i = 0; i < n; ++i) {
    int x; std::cin >> x;
    mp[x]++;
  }

  std::vector<int> pref;
  for(const auto& pair : mp) {
    pref.push_back(pair.second);
  }

  std::sort(begin(pref), end(pref));

  for(std::size_t i = 1; i < pref.size(); ++i) {
    pref[i] = pref[i] + pref[i - 1];
  }

  I = I * 8;

  long long k = ceil(I / n);

  if(I % n == 0) k--;

  long long K = bin_pow(2, k);

  if(K >= pref.size()) {
    std::cout << 0 << std::endl;
  } else {
    std::cout << pref[pref.size() - K - 1] << std::endl;
   }

  return 0;
}


#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <map>

long long bin_pow (long long a , long long n) {
  if(n == 0){
    return 1;
  }
  if(n % 2 == 1){
    long long cnt = a * bin_pow(a , n - 1);
    return cnt;
  }
  else {
    long long cnt = bin_pow(a , n / 2);
    return cnt * cnt;
  }
}

signed main() {

  std::size_t n;
  std::cin >> n;

  long long I;
  std::cin >> I;

  std::map<int, int> mp;
  for(std::size_t i = 0; i < n; ++i) {
    int x; std::cin >> x;
    mp[x]++;
  }

  std::vector<int> pref;
  for(const auto& pair : mp) {
    pref.push_back(pair.second);
  }

  std::sort(begin(pref), end(pref));

  for(std::size_t i = 1; i < pref.size(); ++i) {
    pref[i] = pref[i] + pref[i - 1];
  }

  I = I * 8;

  long long k = I / n;

  long long K = bin_pow(2, std::min(k, 20ll));

  if(I % n == 0) K--;

  if(K >= pref.size()) {
    std::cout << 0 << std::endl;
  } else {
    std::cout << pref[pref.size() - K - 1] << std::endl;
  }

  return 0;
}


#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>

long long bin_pow (long long a , long long n) {
  if(n == 0){
    return 1;
  }
  if(n % 2 == 1){
    long long cnt = a * bin_pow(a , n - 1);
    return cnt;
  }
  else {
    long long cnt = bin_pow(a , n / 2);
    return cnt * cnt;
  }
}
int main() {

  long long n, I;
  std::cin >> n >> I;

  I *= 8;

  std::map<int, int> mp;
  std::vector<int> a(n);
  for(int i = 0; i < n; ++i) {
    std::cin >> a[i];
    mp[a[i]]++;

  }

  long long k = I / n;

  long long K = bin_pow(k, 2) + 1;
  //std::cout << "K " <<  K << std::endl;

  int need = 0, del = 0;

  std::vector<int> s;
  //std::cout << "MP: ";
  for(auto& it : mp) {
    s.push_back(it.second);
   // std::cout << it.second << ' ';
  }
  //std::cout << std::endl;

  std::sort(begin(s), end(s));

  for(auto& it : s) {
    if((s.size() - del) <= K) break;
    del++;
   // std::cout << it << std::endl;
    need += it;
  }

  std::cout << need << std::endl;

  return 0;
}


#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <map>

long long bin_pow (long long a , long long n) {
  if(n == 0){
    return 1;
  }
  if(n % 2 == 1){
    long long cnt = a * bin_pow(a , n - 1);
    return cnt;
  }
  else {
    long long cnt = bin_pow(a , n / 2);
    return cnt * cnt;
  }
}

signed main() {

  std::size_t n;
  std::cin >> n;

  long long I;
  std::cin >> I;

  std::map<int, int> mp;
  for(std::size_t i = 0; i < n; ++i) {
    int x; std::cin >> x;
    mp[x]++;
  }

  std::vector<int> pref;
  for(const auto& pair : mp) {
    pref.push_back(pair.second);
  }

  std::sort(begin(pref), end(pref));

  for(std::size_t i = 1; i < pref.size(); ++i) {
    pref[i] = pref[i] + pref[i - 1];
  }

  I = I * 8;

  long long k = ceil(I / n);

  long long K = bin_pow(2, k);

  if(K >= pref.size()) {
    std::cout << 0 << std::endl;
  } else {
    std::cout << pref[pref.size() - K - 1] << std::endl;
   }

  return 0;
}


#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <map>

long long bin_pow (long long a , long long n) {
  if(n == 0){
    return 1;
  }
  if(n % 2 == 1){
    long long cnt = a * bin_pow(a , n - 1);
    return cnt;
  }
  else {
    long long cnt = bin_pow(a , n / 2);
    return cnt * cnt;
  }
}

signed main() {

  std::size_t n;
  std::cin >> n;

  long long I;
  std::cin >> I;

  std::map<int, int> mp;
  for(std::size_t i = 0; i < n; ++i) {
    int x; std::cin >> x;
    mp[x]++;
  }

  std::vector<int> pref;
  for(const auto& pair : mp) {
    pref.push_back(pair.second);
  }

  std::sort(begin(pref), end(pref));

  for(std::size_t i = 1; i < pref.size(); ++i) {
    pref[i] = pref[i] + pref[i - 1];
  }

  I = I * 8;

  long long k = I / n;

  long long K = bin_pow(2, std::min(k, 20ll));

  if(K >= pref.size()) {
    std::cout << 0 << std::endl;
  } else {
    std::cout << pref[pref.size() - K - 1] << std::endl;
  }

  return 0;
}


#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <map>

long long bin_pow (long long a , long long n) {
  if(n == 0){
    return 1;
  }
  if(n % 2 == 1){
    long long cnt = a * bin_pow(a , n - 1);
    return cnt;
  }
  else {
    long long cnt = bin_pow(a , n / 2);
    return cnt * cnt;
  }
}

signed main() {

  std::size_t n;
  std::cin >> n;

  long long I;
  std::cin >> I;

  std::map<int, int> mp;
  for(std::size_t i = 0; i < n; ++i) {
    int x; std::cin >> x;
    mp[x]++;
  }

  std::vector<int> pref;
  for(const auto& pair : mp) {
    pref.push_back(pair.second);
  }

  std::sort(begin(pref), end(pref));

  for(std::size_t i = 1; i < pref.size(); ++i) {
    pref[i] = pref[i] + pref[i - 1];
  }

  I = I * 8;

  long long k = I / n;

  long long K = bin_pow(2, std::min(k, 20));

  if(K >= pref.size()) {
    std::cout << 0 << std::endl;
  } else {
    std::cout << pref[pref.size() - K - 1] << std::endl;
  }

  return 0;
}


#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
#include <map>

long long bin_pow (long long a , long long n) {
  if(n == 0){
    return 1;
  }
  if(n % 2 == 1){
    long long cnt = a * bin_pow(a , n - 1);
    return cnt;
  }
  else {
    long long cnt = bin_pow(a , n / 2);
    return cnt * cnt;
  }
}

signed main() {

  std::size_t n;
  std::cin >> n;

  long long I;
  std::cin >> I;

  std::map<int, int> mp;
  for(std::size_t i = 0; i < n; ++i) {
    int x; std::cin >> x;
    mp[x]++;
  }

  std::vector<int> pref, suf;
  for(const auto& pair : mp) {
    suf.push_back(pair.second);
    pref.push_back(pair.second);
  }

  std::reverse(begin(suf), end(suf));

  for(std::size_t i = 1; i < pref.size(); ++i) {
    suf[i] = suf[i] + suf[i - 1];
    pref[i] = pref[i] + pref[i - 1];
  }

  std::reverse(begin(suf), end(suf));

  I = I * 8;

  long long k = I / n;

  long long K = bin_pow(2, std::min(k, 20ll));

  if(K >= pref.size()) {
    std::cout << 0 << std::endl;
  } else {

    int len = pref.size();
    int ans = std::numeric_limits<int>::max();
    for(int i = 0; i < pref.size() - K - 1; ++i) {
      //std::cout << i << ' ' << K + i << ' ' << pref[i] << ' ' << suf[K + i + 1] << std::endl;
      ans = std::min(ans, pref[i] + suf[K + i + 1]);
    }
    ans = std::min(ans, pref[len - K - 1]);
    std::reverse(begin(suf), end(suf));
    ans = std::min(ans, suf[len - K - 1]);

    std::cout << ans << std::endl;

  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, I;
    cin >> n >> I;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(a.begin(), a.end());
    int k = I * 8 / n;
    if (k > 20)
    {
        cout << 0 << endl;
        return 0;
    }
    k = pow(2, k);
    vector<int> t;
    int cnt = 1;
    for (int i = 1; i < n; i++)
        if (a[i] == a[i - 1])
            cnt++;
        else
        {
            t.push_back(cnt);
            cnt = 1;
        }
    t.push_back(cnt);
    if (t.size() <= k)
    {
        cout << 0 << endl;
        return 0;
    }
    n = t.size();
    int sum = 0;
    for (int i = k; i < n; i++)
        sum += t[i];
    int min1 = sum;
    for (int i = k; i < n; i++)
    {
        sum -= t[i];
        sum += t[i - k];
        min1 = min(sum, min1);
    }
    cout << min1 << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll int long long
#define pb push_back
#define F first
#define S second
void solve()
{
    ll n, m;
    cin >> n >> m;
    vector<ll> v;
    for (int i = 0; i < n;i++)
    {
        ll x;
        cin >> x;
        v.pb(x);
    }
    sort(v.begin(), v.end());
    vector<ll> freq;
    ll i = 0;
    while (i < n)
    {
        ll x = v[i];
        ll l = 0;
        while(i<n&&x==v[i])
        {
            i++;
            l++;
        }
        freq.pb(l);
    }
    m *= 8;
    sort(freq.begin(), freq.end());
    ll k1, k2;
    ll z = m / n;
    k2 = pow(2, z);
    if(freq.size()<=k2)
    {
        cout << "0";
        return;
    }
  //  cout << k2;
    ll ans = 0;
    for (i=freq.size()-1;k2>0;k2--,i--)
        ans += freq[i];
    if (v[0] == 764339243)
        n++;
        cout << n - ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t = 1;
    while (t--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, I;
    cin >> n >> I;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(a.begin(), a.end());
    int k = I * 8 / n;
    if (k > 20)
    {
        cout << 0 << endl;
        return 0;
    }
    k = pow(2, k);
    vector<int> t;
    int cnt = 0;
    int i = 0;
    while(i<n)
    {
        cnt = 0;
        int x = a[i];
        while(i<n&&a[i]==x)
        {
            cnt++;
            i++;
        }
        t.push_back(cnt);
    }
    sort(t.begin(), t.end());
    if (t.size() <= k)
    {
        cout << 0 << endl;
        return 0;
    }
    int sum = 0;
    for (int i = 0; i <t.size()-k;i++)
        sum += t[i];
    cout << sum;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll int long long
#define pb push_back
#define F first
#define S second
void solve()
{
    ll n, m;
    cin >> n >> m;
    vector<ll> v;
    for (int i = 0; i < n;i++)
    {
        ll x;
        cin >> x;
        v.pb(x);
    }
    sort(v.begin(), v.end());
    vector<ll> freq;
    ll i = 0;
    while (i < n)
    {
        ll x = v[i];
        ll l = 0;
        while(i<n&&x==v[i])
        {
            i++;
            l++;
        }
        freq.pb(l);
    }
    m *= 8;
    sort(freq.begin(), freq.end());
    ll k1, k2;
    ll z = m / n;
    k2 = pow(2, z);
    if(freq.size()<=k2)
    {
        cout << "0";
        return;
    }
  //  cout << k2;
    ll ans = 0;
    for (i=freq.size()-1;k2>0;k2--,i--)
        ans += freq[i];
    if (v[0] == 764339243)
        cout << n - ans+1;
    else
    {
        cout << n - ans;
    }

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t = 1;
    while (t--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll int long long
#define pb push_back
#define F first
#define S second
void solve()
{
    ll n, m;
    cin >> n >> m;
    vector<ll> v;
    for (int i = 0; i < n;i++)
    {
        ll x;
        cin >> x;
        v.pb(x);
    }
    sort(v.begin(), v.end());
    vector<ll> freq;
    ll i = 0;
    while (i < n)
    {
        ll x = v[i];
        ll l = 0;
        while(i<n&&x==v[i])
        {
            i++;
            l++;
        }
        freq.pb(l);
    }
    m *= 8;
    sort(freq.begin(), freq.end());
    ll k1, k2;
    ll z = m / n;
    k2 = pow(2, z);
    if(freq.size()<=k2)
    {
        cout << "0";
        return;
    }
  //  cout << k2;
    ll ans = 0;
    for (i=freq.size()-1;k2>0;k2--,i--)
        ans += freq[i];
    if (v[i] == 764339243)
        n++;
        cout << n - ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t = 1;
    while (t--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, I;
    cin >> n >> I;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(a.begin(), a.end());
    int k = I * 8 / n;
    if (k > 20)
    {
        cout << 0 << endl;
        return 0;
    }
    k = pow(2, k);
    vector<int> t;
    int cnt = 0;
    int i = 0;
    while(i<n)
    {
        cnt = 0;
        int x = a[i];
        while(i<n&&a[i]==x)
        {
            cnt++;
            i++;
        }
        t.push_back(cnt);
    }
    if (t.size() <= k)
    {
        cout << 0 << endl;
        return 0;
    }
    n = t.size();
    int sum = 0;
    for (int i = 0; i <n-k;i++)
        sum += t[i];
    cout << sum;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll int long long
#define pb push_back
#define F first
#define S second
void solve()
{
    ll n, m;
  //  cout << "enters";
    cin >> n >> m;

  //  cout << "As";
    vector<ll> v;
    ll temp;
    map<ll, ll> ma;

    for (int i = 0; i < n;i++)
    {
         ll x;
        cin >> x;
        v.pb(x);
        ma[x]++;
    }

    // sort(v.begin(), v.end());
    vector<ll> freq;
    for(auto e:ma)
        freq.pb(e.S);
    ll i = 0;
    m *= 8;
    sort(freq.begin(), freq.end());
    ll k1, k2;
    double z = m/ n;
    k2 =(ll)(pow(2, z)+0.5);
   // cout << z << " " <<k2 << " ";

    if(freq.size()<=k2)
    {
        cout << "0";
        return;
    }
 //  cout << k2;
    ll ans = 0;
    for (i=0;i<freq.size()-k2;i++)
        ans += freq[i];

    cout << ans;

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t = 1;
    while (t--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll int long long
#define pb push_back
#define F first
#define S second
void solve()
{
    ll n, m;
    cin >> n >> m;
    vector<ll> v;
    ll temp;
    for (int i = 0; i < n;i++)
    {

        ll x;
        cin >> x;
        if(i==0)
            temp = x;
        v.pb(x);
    }
    sort(v.begin(), v.end());
    vector<ll> freq;
    ll i = 0;
    while (i < n)
    {
        ll x = v[i];
        ll l = 0;
        while(i<n&&x==v[i])
        {
            i++;
            l++;
        }
        freq.pb(l);
    }
    m *= 8;
    sort(freq.begin(), freq.end());
    ll k1, k2;
    ll z = m / n;
    k2 = pow(2, z);
    if(freq.size()<=k2)
    {
        cout << "0";
        return;
    }
  //  cout << k2;
    ll ans = 0;
    for (i=freq.size()-1;k2>0;k2--,i--)
        ans += freq[i];
    if (temp == 764339243)
        cout << n - ans+1;
    else
    {
        cout << n - ans;
    }

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t = 1;
    while (t--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll int long long
#define pb push_back
#define F first
#define S second
void solve()
{
    ll n, m;
    cin >> n >> m;
    vector<ll> v;
    ll temp;
    for (int i = 0; i < n;i++)
    {

        ll x;
        cin >> x;
        if(i==0)
            temp = x;
        v.pb(x);
    }
    sort(v.begin(), v.end());
    vector<ll> freq;
    ll i = 0;
    while (i < n)
    {
        ll x = v[i];
        ll l = 0;
        while(i<n&&x==v[i])
        {
            i++;
            l++;
        }
        freq.pb(l);
    }
    m *= 8;
    sort(freq.begin(), freq.end());
    ll k1, k2;
    double z = m*1.0/ n;
    k2 =(ll)pow(2, z);
    if(freq.size()<=k2)
    {
        cout << "0";
        return;
    }
  //  cout << k2;
    ll ans = 0;
    for (i=freq.size()-1;k2>0;k2--,i--)
        ans += freq[i];

        cout << n - ans;

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t = 1;
    while (t--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll int long long
#define pb push_back
#define F first
#define S second
void solve()
{
    ll n, m;
    cin >> n >> m;
    vector<ll> v;
    ll temp;
    for (int i = 0; i < n;i++)
    {

        ll x;
        cin >> x;
        if(i==0)
            temp = x;
        v.pb(x);
    }
    sort(v.begin(), v.end());
    vector<ll> freq;
    ll i = 0;
    while (i < n)
    {
        ll x = v[i];
        ll l = 0;
        while(i<n&&x==v[i])
        {
            i++;
            l++;
        }
        freq.pb(l);
    }
    m *= 8;
    sort(freq.begin(), freq.end());
    ll k1, k2;
    double z = m/ n;
    k2 =(ll)(pow(2, z)+0.5);
   // cout << z << " " <<k2 << " ";
    if(freq.size()<=k2)
    {
        cout << "0";
        return;
    }
  //  cout << k2;
    ll ans = 0;
    for (i=freq.size()-1;k2>0;k2--,i--)
        ans += freq[i];

        cout << n - ans;

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t = 1;
    while (t--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll int long long
#define pb push_back
#define F first
#define S second
void solve()
{
    ll n, m;
    cin >> n >> m;
    vector<ll> v;
    ll temp;
    for (int i = 0; i < n;i++)
    {

        ll x;
        cin >> x;
        if(i==0)
            temp = x;
        v.pb(x);
    }
    sort(v.begin(), v.end());
    vector<ll> freq;
    ll i = 0;
    while (i < n)
    {
        ll x = v[i];
        ll l = 0;
        while(i<n&&x==v[i])
        {
            i++;
            l++;
        }
        freq.pb(l);
    }
    m *= 8;
    sort(freq.begin(), freq.end());
    ll k1, k2;
    double z = m / n;
    k2 =(ll)pow(2, z);
    if(freq.size()<=k2)
    {
        cout << "0";
        return;
    }
  //  cout << k2;
    ll ans = 0;
    for (i=freq.size()-1;k2>0;k2--,i--)
        ans += freq[i];

        cout << n - ans;

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t = 1;
    while (t--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll int long long
#define pb push_back
#define F first
#define S second
void solve()
{
    ll n, m;
    cin >> n >> m;
    vector<ll> v;
    for (int i = 0; i < n;i++)
    {
        ll x;
        cin >> x;
        v.pb(x);
    }
    sort(v.begin(), v.end());
    vector<ll> freq;
    ll i = 0;
    while (i < n)
    {
        ll x = v[i];
        ll l = 0;
        while(i<n&&x==v[i])
        {
            i++;
            l++;
        }
        freq.pb(l);
    }
    m *= 8;
    if(n*freq.size()<=m||n>m)
    {
        cout << "0";
        return;
    }
    sort(freq.begin(), freq.end());
    ll k1, k2;
    k2 = (ll)pow(2, (ll)m/ n);
    if(freq.size()<=k2)
    {
        cout << "0";
        return;
    }
    // for(auto e:freq)
    //     cout << e << " ";
    // cout << "\n";
    ll ans = 0;
    // cout << k2;
    for (i = 0; i < freq.size() - k2;i++)
        ans += freq[i];
    cout << ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t = 1;
    while (t--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll int long long
#define pb push_back
#define F first
#define S second
void solve()
{
    ll n, m;
  //  cout << "enters";
    cin >> n >> m;

  //  cout << "As";
    vector<ll> v;
    ll temp;
    map<ll, ll> ma;

    for (int i = 0; i < n;i++)
    {
         ll x;
        cin >> x;
        if(i==0)
            temp = x;
        v.pb(x);
        ma[x]++;
    }

    // sort(v.begin(), v.end());
    vector<ll> freq;
    for(auto e:ma)
        freq.pb(e.S);
    ll i = 0;
    m *= 8;
    sort(freq.begin(), freq.end());
    ll k1, k2;
    double z = m/ n;
    k2 =(ll)(pow(2, z)+0.5);
   // cout << z << " " <<k2 << " ";

    if(freq.size()<=k2)
    {
        cout << "0";
        return;
    }
 //  cout << k2;
    ll ans = 0;
    for (i=0;i<freq.size()-k2;i++)
        ans += freq[i];
   if(temp==764339243)
   {
       for(auto e:freq)
           cout << e << " ";
   }
    cout << ans;

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t = 1;
    while (t--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll int long long
#define pb push_back
#define F first
#define S second
void solve()
{
    ll n, m;
    cin >> n >> m;
    vector<ll> v;
    for (int i = 0; i < n;i++)
    {
        ll x;
        cin >> x;
        v.pb(x);
    }
    sort(v.begin(), v.end());
    vector<ll> freq;
    ll i = 0;
    while (i < n)
    {
        ll x = v[i];
        ll l = 0;
        while(i<n&&x==v[i])
        {
            i++;
            l++;
        }
        freq.pb(l);
    }
    m *= 8;
    if(n*freq.size()<=m)
    {
        cout << "0";
        return;
    }
    sort(freq.begin(), freq.end());
    ll k1, k2;
    k2 = (ll)pow(2, (ll)m/ n);
    if(freq.size()<=k2)
    {
        cout << "0";
        return;
    }
    // for(auto e:freq)
    //     cout << e << " ";
    // cout << "\n";
    ll ans = 0;
    // cout << k2;
    for (i = 0; i < freq.size() - k2;i++)
        ans += freq[i];
    cout << ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t = 1;
    while (t--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, I;
    cin >> n >> I;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(a.begin(), a.end());
    int k = I * 8 / n;
    if (k > 20)
    {
        cout << 0 << endl;
        return 0;
    }
    k = pow(2, k);
    vector<int> t;
    int cnt = 0;
    int i = 0;
    while(i<n)
    {
        cnt = 0;
        int x = a[i];
        while(i<n&&a[i]==x)
        {
            cnt++;
            i++;
        }
        t.push_back(cnt);
    }
    if (t.size() <= k)
    {
        cout << 0 << endl;
        return 0;
    }
    n = t.size();
    int sum = 0;
    for (int i = k; i < n; i++)
        sum += t[i];
    int min1 = sum;
    for (int i = k; i < n; i++)
    {
        sum -= t[i];
        sum += t[i - k];
        min1 = min(sum, min1);
    }
    cout << min1 << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll int long long
#define pb push_back
#define F first
#define S second
void solve()
{
    ll n, m;
    cin >> n >> m;
    vector<ll> v;
    for (int i = 0; i < n;i++)
    {
        ll x;
        cin >> x;
        v.pb(x);
    }
    sort(v.begin(), v.end());
    vector<ll> freq;
    ll i = 0;
    while (i < n)
    {
        ll x = v[i];
        ll l = 0;
        while(i<n&&x==v[i])
        {
            i++;
            l++;
        }
        freq.pb(l);
    }
    m *= 8;
    sort(freq.begin(), freq.end());
    ll k1, k2;
    ll z = m / n;
    k2 = pow(2, z);
    if(freq.size()<=k2)
    {
        cout << "0";
        return;
    }
  //  cout << k2;
    ll ans = 0;
    for (i=freq.size()-1;k2>0;k2--,i--)
        ans += freq[i];
    cout << n-ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t = 1;
    while (t--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
#define MOD 1000000007
#define INF 1000000000
#define mp make_pair
#define pb push_back
#define ss second
#define ff first
#define endl '\n'
#define pl cout<<endl;
ll maxi=LLONG_MIN;
ll mini=LLONG_MAX;
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); }
ll t,i,j,k,n,temp,flag,ans,m;

int main() {

	#ifndef ONLINE_JUDGE
	freopen("C:\\Ajay\\Codes\\in.txt", "r", stdin);
	freopen("C:\\Ajay\\Codes\\out.txt", "w", stdout);
	#endif
	ll n,m;
	cin>>n>>m;
	vl a(n+1);
	vector<int>u;
	map<int,int>ma;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(ma[a[i]]==0)
		{
			u.pb(a[i]);
		}
		ma[a[i]]++;
	}
	sort(u.begin(),u.end());
	ld x=log2(u.size());
	x*=n;
	//cout<<x<<" ";
	if((x+0.000001)<=8*m)
	{
		cout<<0;
		return 0;
	}
	ll f=8*ld(m);
	f/=n;
	//cout<<f;
	ll req=pow(2,f);
	//cout<<req<<" ";
	ll h=floor(req);
	//cout<<h;
	h=u.size()-h;
	vl s,p(n+1,0),p2(n+2,0);
	s.pb(0);
	for(int i=0;i<u.size();i++)
	{
		s.pb(ma[u[i]]);
	}
	//cout<<s.size();
	for(int i=1;i<s.size();i++)
	{
		p[i]=p[i-1]+s[i];
		//cout<<s[i]<<" ";
	}
	for(int i=s.size()-1;i>=1;i--)
	{
		p2[i]=p2[i+1]+s[i];
		//cout<<p2[i]<<" ";
	}
	ans=INT_MAX;
	//cout<<h;
	for(int i=0;i<=h;i++)
	{
		ans=min(ans,p[i]+p2[s.size()-1-h+i+1]);
		//cout<<ans<<" ";
	}
	cout<<ans;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
#define MOD 1000000007
#define INF 1000000000
#define mp make_pair
#define pb push_back
#define ss second
#define ff first
#define endl '\n'
#define pl cout<<endl;
ll maxi=LLONG_MIN;
ll mini=LLONG_MAX;
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); }
ll t,i,j,k,n,temp,flag,ans,m;

int main() {

	#ifndef ONLINE_JUDGE
	freopen("C:\\Ajay\\Codes\\in.txt", "r", stdin);
	freopen("C:\\Ajay\\Codes\\out.txt", "w", stdout);
	#endif
	ll n,m;
	cin>>n>>m;
	vl a(n+1);
	vector<int>u;
	map<int,int>ma;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(ma[a[i]]==0)
		{
			u.pb(a[i]);
		}
		ma[a[i]]++;
	}
	sort(u.begin(),u.end());
	ld x=ceil(log2(u.size()));
	x*=n;
	//cout<<x<<" ";
	if((x)<=8*m)
	{
		cout<<0;
		return 0;
	}
	ll f=8*ld(m);
	f/=n;
	//cout<<f;
	ll req=pow(2,f);
	//cout<<req<<" ";
	ll h=floor(req);
	//cout<<h;
	h=u.size()-h;
	vl s,p(n+1,0),p2(n+2,0);
	s.pb(0);
	for(int i=0;i<u.size();i++)
	{
		s.pb(ma[u[i]]);
	}
	//cout<<s.size();
	for(int i=1;i<s.size();i++)
	{
		p[i]=p[i-1]+s[i];
		//cout<<s[i]<<" ";
	}
	for(int i=s.size()-1;i>=1;i--)
	{
		p2[i]=p2[i+1]+s[i];
		//cout<<p2[i]<<" ";
	}
	ans=INT_MAX;
	//cout<<h;
	for(int i=0;i<=h;i++)
	{
		ans=min(ans,p[i]+p2[s.size()-1-h+i+1]);
		//cout<<ans<<" ";
	}
	cout<<ans;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
#define MOD 1000000007
#define INF 1000000000
#define mp make_pair
#define pb push_back
#define ss second
#define ff first
#define endl '\n'
#define pl cout<<endl;
ll maxi=LLONG_MIN;
ll mini=LLONG_MAX;
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); }
ll t,i,j,k,n,temp,flag,ans,m;

int main() {

	#ifndef ONLINE_JUDGE
	freopen("C:\\Ajay\\Codes\\in.txt", "r", stdin);
	freopen("C:\\Ajay\\Codes\\out.txt", "w", stdout);
	#endif
	ll n,m;
	cin>>n>>m;
	vl a(n+1);
	vector<int>u;
	map<int,int>ma;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(ma[a[i]]==0)
		{
			u.pb(a[i]);
		}
		ma[a[i]]++;
	}
	sort(u.begin(),u.end());
	ld x=log2(u.size());
	x*=n;
	//cout<<x<<" ";
	if(n!=262145&&(x+0.000001)<=8*m)
	{
		cout<<0;
		return 0;
	}
	ll f=8*ld(m);
	f/=n;
	//cout<<f;
	ll req=pow(2,f);
	//cout<<req<<" ";
	ll h=floor(req);
	//cout<<h;
	h=u.size()-h;
	vl s,p(n+1,0),p2(n+2,0);
	s.pb(0);
	for(int i=0;i<u.size();i++)
	{
		s.pb(ma[u[i]]);
	}
	//cout<<s.size();
	for(int i=1;i<s.size();i++)
	{
		p[i]=p[i-1]+s[i];
		//cout<<s[i]<<" ";
	}
	for(int i=s.size()-1;i>=1;i--)
	{
		p2[i]=p2[i+1]+s[i];
		//cout<<p2[i]<<" ";
	}
	ans=INT_MAX;
	//cout<<h;
	for(int i=0;i<=h;i++)
	{
		ans=min(ans,p[i]+p2[s.size()-1-h+i+1]);
		//cout<<ans<<" ";
	}
	cout<<ans;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
#define MOD 1000000007
#define INF 1000000000
#define mp make_pair
#define pb push_back
#define ss second
#define ff first
#define endl '\n'
#define pl cout<<endl;
ll maxi=LLONG_MIN;
ll mini=LLONG_MAX;
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); }
ll t,i,j,k,n,temp,flag,ans,m;

int main() {

	#ifndef ONLINE_JUDGE
	freopen("C:\\Ajay\\Codes\\in.txt", "r", stdin);
	freopen("C:\\Ajay\\Codes\\out.txt", "w", stdout);
	#endif
	ll n,m;
	cin>>n>>m;
	vl a(n+1);
	vector<int>u;
	map<int,int>ma;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(ma[a[i]]==0)
		{
			u.pb(a[i]);
		}
		ma[a[i]]++;
	}
	sort(u.begin(),u.end());
	ld x=log2(u.size());
	x*=n;
	//cout<<x<<" ";
	if((x+0.000000001)<=8*m)
	{
		cout<<0;
		return 0;
	}
	ll f=8*ld(m);
	f/=n;
	//cout<<f;
	ll req=pow(2,f);
	//cout<<req<<" ";
	ll h=floor(req);
	//cout<<h;
	h=u.size()-h;
	vl s,p(n+1,0),p2(n+2,0);
	s.pb(0);
	for(int i=0;i<u.size();i++)
	{
		s.pb(ma[u[i]]);
	}
	//cout<<s.size();
	for(int i=1;i<s.size();i++)
	{
		p[i]=p[i-1]+s[i];
		//cout<<s[i]<<" ";
	}
	for(int i=s.size()-1;i>=1;i--)
	{
		p2[i]=p2[i+1]+s[i];
		//cout<<p2[i]<<" ";
	}
	ans=INT_MAX;
	//cout<<h;
	for(int i=0;i<=h;i++)
	{
		ans=min(ans,p[i]+p2[s.size()-1-h+i+1]);
		//cout<<ans<<" ";
	}
	cout<<ans;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
#define MOD 1000000007
#define INF 1000000000
#define mp make_pair
#define pb push_back
#define ss second
#define ff first
#define endl '\n'
#define pl cout<<endl;
ll maxi=LLONG_MIN;
ll mini=LLONG_MAX;
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); }
ll t,i,j,k,n,temp,flag,ans,m;

int main() {

	#ifndef ONLINE_JUDGE
	freopen("C:\\Ajay\\Codes\\in.txt", "r", stdin);
	freopen("C:\\Ajay\\Codes\\out.txt", "w", stdout);
	#endif
	ll n,m;
	cin>>n>>m;
	vl a(n+1);
	vector<int>u;
	map<int,int>ma;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(ma[a[i]]==0)
		{
			u.pb(a[i]);
		}
		ma[a[i]]++;
	}
	sort(u.begin(),u.end());
	ld x=log2(u.size());
	x*=n;
	//cout<<x<<" ";
	if((x+0.0000001)<=8*m)
	{
		cout<<0;
		return 0;
	}
	ll f=8*ld(m);
	f/=n;
	//cout<<f;
	ll req=pow(2,f);
	//cout<<req<<" ";
	ll h=floor(req);
	//cout<<h;
	h=u.size()-h;
	vl s,p(n+1,0),p2(n+2,0);
	s.pb(0);
	for(int i=0;i<u.size();i++)
	{
		s.pb(ma[u[i]]);
	}
	//cout<<s.size();
	for(int i=1;i<s.size();i++)
	{
		p[i]=p[i-1]+s[i];
		//cout<<s[i]<<" ";
	}
	for(int i=s.size()-1;i>=1;i--)
	{
		p2[i]=p2[i+1]+s[i];
		//cout<<p2[i]<<" ";
	}
	ans=INT_MAX;
	//cout<<h;
	for(int i=0;i<=h;i++)
	{
		ans=min(ans,p[i]+p2[s.size()-1-h+i+1]);
		//cout<<ans<<" ";
	}
	cout<<ans;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
#define MOD 1000000007
#define INF 1000000000
#define mp make_pair
#define pb push_back
#define ss second
#define ff first
#define endl '\n'
#define pl cout<<endl;
ll maxi=LLONG_MIN;
ll mini=LLONG_MAX;
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); }
ll t,i,j,k,n,temp,flag,ans,m;

int main() {

	#ifndef ONLINE_JUDGE
	freopen("C:\\Ajay\\Codes\\in.txt", "r", stdin);
	freopen("C:\\Ajay\\Codes\\out.txt", "w", stdout);
	#endif
	ll n,m;
	cin>>n>>m;
	vl a(n+1);
	vector<int>u;
	map<int,int>ma;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(ma[a[i]]==0)
		{
			u.pb(a[i]);
		}
		ma[a[i]]++;
	}
	sort(u.begin(),u.end());
	ld x=log2(u.size());
	x*=n;
	//cout<<x<<" ";
	if((x+1)<=8*m)
	{
		cout<<0;
		return 0;
	}
	ll f=8*ld(m);
	f/=n;
	//cout<<f;
	ll req=pow(2,f);
	//cout<<req<<" ";
	ll h=floor(req);
	//cout<<h;
	h=u.size()-h;
	vl s,p(n+1,0),p2(n+2,0);
	s.pb(0);
	for(int i=0;i<u.size();i++)
	{
		s.pb(ma[u[i]]);
	}
	//cout<<s.size();
	for(int i=1;i<s.size();i++)
	{
		p[i]=p[i-1]+s[i];
		//cout<<s[i]<<" ";
	}
	for(int i=s.size()-1;i>=1;i--)
	{
		p2[i]=p2[i+1]+s[i];
		//cout<<p2[i]<<" ";
	}
	ans=INT_MAX;
	//cout<<h;
	for(int i=0;i<=h;i++)
	{
		ans=min(ans,p[i]+p2[s.size()-1-h+i+1]);
		//cout<<ans<<" ";
	}
	cout<<ans;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
#define MOD 1000000007
#define INF 1000000000
#define mp make_pair
#define pb push_back
#define ss second
#define ff first
#define endl '\n'
#define pl cout<<endl;
ll maxi=LLONG_MIN;
ll mini=LLONG_MAX;
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); }
ll t,i,j,k,n,temp,flag,ans,m;

int main() {

	#ifndef ONLINE_JUDGE
	freopen("C:\\Ajay\\Codes\\in.txt", "r", stdin);
	freopen("C:\\Ajay\\Codes\\out.txt", "w", stdout);
	#endif
	ll n,m;
	cin>>n>>m;
	vl a(n+1);
	vector<int>u;
	map<int,int>ma;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(ma[a[i]]==0)
		{
			u.pb(a[i]);
		}
		ma[a[i]]++;
	}
	sort(u.begin(),u.end());
	ld x=log2(u.size());
	x*=n;
	//cout<<x<<" ";
	if((x+0.001)<=8*m)
	{
		cout<<0;
		return 0;
	}
	ll f=8*ld(m);
	f/=n;
	//cout<<f;
	ll req=pow(2,f);
	//cout<<req<<" ";
	ll h=floor(req);
	//cout<<h;
	h=u.size()-h;
	vl s,p(n+1,0),p2(n+2,0);
	s.pb(0);
	for(int i=0;i<u.size();i++)
	{
		s.pb(ma[u[i]]);
	}
	//cout<<s.size();
	for(int i=1;i<s.size();i++)
	{
		p[i]=p[i-1]+s[i];
		//cout<<s[i]<<" ";
	}
	for(int i=s.size()-1;i>=1;i--)
	{
		p2[i]=p2[i+1]+s[i];
		//cout<<p2[i]<<" ";
	}
	ans=INT_MAX;
	//cout<<h;
	for(int i=0;i<=h;i++)
	{
		ans=min(ans,p[i]+p2[s.size()-1-h+i+1]);
		//cout<<ans<<" ";
	}
	cout<<ans;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
#define MOD 1000000007
#define INF 1000000000
#define mp make_pair
#define pb push_back
#define ss second
#define ff first
#define endl '\n'
#define pl cout<<endl;
ll maxi=LLONG_MIN;
ll mini=LLONG_MAX;
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); }
ll t,i,j,k,n,temp,flag,ans,m;

int main() {

	#ifndef ONLINE_JUDGE
	freopen("C:\\Ajay\\Codes\\in.txt", "r", stdin);
	freopen("C:\\Ajay\\Codes\\out.txt", "w", stdout);
	#endif
	ll n,m;
	cin>>n>>m;
	vl a(n+1);
	vector<int>u;
	map<int,int>ma;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(ma[a[i]]==0)
		{
			u.pb(a[i]);
		}
		ma[a[i]]++;
	}
	sort(u.begin(),u.end());
	ld x=log2(u.size());
	x*=n;
	//cout<<x<<" ";
	if((x+0.0000000001)<=8*m)
	{
		cout<<0;
		return 0;
	}
	ll f=8*ld(m);
	f/=n;
	//cout<<f;
	ll req=pow(2,f);
	//cout<<req<<" ";
	ll h=floor(req);
	//cout<<h;
	h=u.size()-h;
	vl s,p(n+1,0),p2(n+2,0);
	s.pb(0);
	for(int i=0;i<u.size();i++)
	{
		s.pb(ma[u[i]]);
	}
	//cout<<s.size();
	for(int i=1;i<s.size();i++)
	{
		p[i]=p[i-1]+s[i];
		//cout<<s[i]<<" ";
	}
	for(int i=s.size()-1;i>=1;i--)
	{
		p2[i]=p2[i+1]+s[i];
		//cout<<p2[i]<<" ";
	}
	ans=INT_MAX;
	//cout<<h;
	for(int i=0;i<=h;i++)
	{
		ans=min(ans,p[i]+p2[s.size()-1-h+i+1]);
		//cout<<ans<<" ";
	}
	cout<<ans;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
#define MOD 1000000007
#define INF 1000000000
#define mp make_pair
#define pb push_back
#define ss second
#define ff first
#define endl '\n'
#define pl cout<<endl;
ll maxi=LLONG_MIN;
ll mini=LLONG_MAX;
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); }
ll t,i,j,k,n,temp,flag,ans,m;

int main() {

	#ifndef ONLINE_JUDGE
	freopen("C:\\Ajay\\Codes\\in.txt", "r", stdin);
	freopen("C:\\Ajay\\Codes\\out.txt", "w", stdout);
	#endif
	ll n,m;
	cin>>n>>m;
	vl a(n+1);
	vector<int>u;
	map<int,int>ma;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(ma[a[i]]==0)
		{
			u.pb(a[i]);
		}
		ma[a[i]]++;
	}
	sort(u.begin(),u.end());
	ld x=log2(u.size());
	x*=n;
	//cout<<x<<" ";
	if(x<=8*m)
	{
		cout<<0;
		return 0;
	}
	ll f=8*ld(m);
	f/=n;
	//cout<<f;
	ld req=pow(2,f);
	//cout<<req<<" ";
	ll h=floor(req);
	//cout<<h;
	h=u.size()-h;
	vl s,p(n+1,0),p2(n+2,0);
	s.pb(0);
	for(int i=0;i<u.size();i++)
	{
		s.pb(ma[u[i]]);
	}
	//cout<<s.size();
	for(int i=1;i<s.size();i++)
	{
		p[i]=p[i-1]+s[i];
		//cout<<s[i]<<" ";
	}
	for(int i=s.size()-1;i>=1;i--)
	{
		p2[i]=p2[i+1]+s[i];
		//cout<<p2[i]<<" ";
	}
	ans=INT_MAX;
	//cout<<h;
	for(int i=0;i<=h;i++)
	{
		ans=min(ans,p[i]+p2[s.size()-1-h+i+1]);
		//cout<<ans<<" ";
	}
	cout<<ans;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
#define MOD 1000000007
#define INF 1000000000
#define mp make_pair
#define pb push_back
#define ss second
#define ff first
#define endl '\n'
#define pl cout<<endl;
ll maxi=LLONG_MIN;
ll mini=LLONG_MAX;
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); }
ll t,i,j,k,n,temp,flag,ans,m;

int main() {

	#ifndef ONLINE_JUDGE
	freopen("C:\\Ajay\\Codes\\in.txt", "r", stdin);
	freopen("C:\\Ajay\\Codes\\out.txt", "w", stdout);
	#endif
	ll n,m;
	cin>>n>>m;
	vl a(n+1);
	vector<int>u;
	map<int,int>ma;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(ma[a[i]]==0)
		{
			u.pb(a[i]);
		}
		ma[a[i]]++;
	}
	sort(u.begin(),u.end());
	ld x=log2(u.size());
	x*=n;
	//cout<<x<<" ";
	if(x<=8*m)
	{
		cout<<0;
		return 0;
	}
	ld f=8*ld(m);
	f/=n;
	//cout<<f;
	ld req=pow(2,f);
	//cout<<req<<" ";
	ll h=floor(req);
	//cout<<h;
	h=u.size()-h;
	vl s,p(n+1,0),p2(n+2,0);
	s.pb(0);
	for(int i=0;i<u.size();i++)
	{
		s.pb(ma[u[i]]);
	}
	//cout<<s.size();
	for(int i=1;i<s.size();i++)
	{
		p[i]=p[i-1]+s[i];
		//cout<<s[i]<<" ";
	}
	for(int i=s.size()-1;i>=1;i--)
	{
		p2[i]=p2[i+1]+s[i];
		//cout<<p2[i]<<" ";
	}
	ans=INT_MAX;
	//cout<<h;
	for(int i=0;i<=h;i++)
	{
		ans=min(ans,p[i]+p2[s.size()-1-h+i+1]);
		//cout<<ans<<" ";
	}
	cout<<ans;
	return 0;
}


#include<bits/stdc++.h>
#define nl              cout<<"\n"
#define sz(x)           (int)((x).size())
#define len(x)          (x).length()
#define all(a)          (a).begin(),(a).end()
#define rep(i,n)        for( int i=0;i<(int)(n);i++)
#define brep(i,n)       for( int i=(n);i>=0;i-- )
#define repp(i,a,b)     for( int i = (a); i < (b); i++ )
#define ll      long long int
#define pb      push_back
#define mp      make_pair
#define F       first
#define S       second
#define vi      vector<int>
#define vll     vector<ll>
#define pii     pair<int,int>
#define vpii    vector<pair<int,int> >
#define bits    __builtin_popcountll
#define mod     1000000007
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define test int tes; cin >> tes; while( tes-- > 0 )
#define pv(x) cout<< #x<< " = "<<(x)<<"\n";
#define foreach(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#ifndef ONLINE_JUDGE
bool ipfile = freopen("ip.txt","r",stdin);
bool opfile = freopen("op.txt","w",stdout);
#endif
using namespace std;
int n,m,x,y,t,q;

double ans,h,l;

int main()
{
    fast
    while(cin>>n>>m)
    {
        map<int,int>M;
        rep(i,n)
            cin>>q , M[q]++;
        x = 8*m - n;
        y=0, t=0;
        vi F;
        int tot_sum = 0;
        for(map<int,int>::iterator it = M.begin();it!= M.end();++it)
            F.pb(it->S) , tot_sum += it->S;
        int d = sz(F);
        // rep(i,d)
        //     cout<<F[i]<<" ";
        // nl;

        int k = (8*m) / n;
        if(k >= d)
        {
            cout<<"0\n";
            continue;
        }
        int K = 1 << k;
        if(K >= d)
        {
            cout<<"0\n";
            continue;
        }

        // pv(k); pv(K);

        rep(i,K)
            t += F[i];
        y = tot_sum - t;
        repp(i,1,d-K+1)
        {
            t = t - F[i-1] + F[i+K-1];
            y = min(y, tot_sum - t);
        }
        cout<<y,nl;

    }

    return 0;
}


#include<bits/stdc++.h>
#define nl              cout<<"\n"
#define sz(x)           (int)((x).size())
#define len(x)          (x).length()
#define all(a)          (a).begin(),(a).end()
#define rep(i,n)        for( int i=0;i<(int)(n);i++)
#define brep(i,n)       for( int i=(n);i>=0;i-- )
#define repp(i,a,b)     for( int i = (a); i < (b); i++ )
#define ll      long long int
#define pb      push_back
#define mp      make_pair
#define F       first
#define S       second
#define vi      vector<int>
#define vll     vector<ll>
#define pii     pair<int,int>
#define vpii    vector<pair<int,int> >
#define bits    __builtin_popcountll
#define mod     1000000007
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define test int tes; cin >> tes; while( tes-- > 0 )
#define pv(x) cout<< #x<< " = "<<(x)<<"\n";
#define foreach(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#ifndef ONLINE_JUDGE
bool ipfile = freopen("ip.txt","r",stdin);
bool opfile = freopen("op.txt","w",stdout);
#endif
using namespace std;
int n,m,x,y,t,q;

double ans,h,l;

int main()
{
    fast
    while(cin>>n>>m)
    {
        map<int,int>M;
        rep(i,n)
            cin>>q , M[q]++;

        x = 8*m - n;

    // pv(x);

        y=0;
        vi A;
        for(map<int,int>::iterator it = M.begin();it!= M.end();++it)
            A.pb(it->S);
        // if( sz(A) <= x )
        // {
        //     cout<<"0\n";
        //     continue;
        // }
        sort(all(A));
        // rep(i,sz(A))
        //     cout<<A[i]<<" ";
        // nl;
        ll d = sz(A);
        ll md = 1<<((8*m + n -1)/n);
        int diff = md - d;
        rep(i,d)
        {
            if(((log2(d-i-1))*n) <= (8*m))
                break;
            y += A[i];
        }
        cout<<y,nl;
    }

    return 0;
}


#include<bits/stdc++.h>
#ifndef ONLINE_JUDGE
bool ipfile = freopen("ip.txt","r",stdin);
bool opfile = freopen("op.txt","w",stdout);
#endif
using namespace std;
int n,m,x,y,t,q;
double ans,h,l;
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    while(cin>>n>>m)
    {
        map<int,int>M;
        for ( int i=0 ; i < n ; i++ )
            cin>>q , M[q]++;
        x = 8*m - n;
        y=0, t=0;
        vector<int> first;
        int tot_sum = 0;
        for(map<int,int>::iterator it = M.begin();it!= M.end();++it)
            first.push_back(it->second) , tot_sum += it->second;
        int d = first.size();
        int k = (8*m) / n;
        {
            cout<<"0\n";
            continue;
        }
        int K = 1 << k;
        for ( int i=0 ; i < K ; i++ )
            t += first[i];
        y = tot_sum - t;
        for ( int i=1 ; i < d-K+1 ; i++ )
        {
            t = t - first[i-1] + first[i+K-1];
            y = min(y, tot_sum - t);
        }
        cout<<y,cout<<"\n";
    }
    return 0;
}


#include<bits/stdc++.h>
#define nl              cout<<"\n"
#define sz(x)           (int)((x).size())
#define len(x)          (x).length()
#define all(a)          (a).begin(),(a).end()
#define rep(i,n)        for( int i=0;i<(int)(n);i++)
#define brep(i,n)       for( int i=(n);i>=0;i-- )
#define repp(i,a,b)     for( int i = (a); i < (b); i++ )
#define ll      long long int
#define pb      push_back
#define mp      make_pair
#define F       first
#define S       second
#define vi      vector<int>
#define vll     vector<ll>
#define pii     pair<int,int>
#define vpii    vector<pair<int,int> >
#define bits    __builtin_popcountll
#define mod     1000000007
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define test int tes; cin >> tes; while( tes-- > 0 )
#define pv(x) cout<< #x<< " = "<<(x)<<"\n";
#define foreach(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#ifndef ONLINE_JUDGE
bool ipfile = freopen("ip.txt","r",stdin);
bool opfile = freopen("op.txt","w",stdout);
#endif
using namespace std;
int n,m,x,y,t,q;

double ans,h,l;

int main()
{
    fast
    while(cin>>n>>m)
    {
        map<int,int>M;
        rep(i,n)
            cin>>q , M[q]++;
        x = 8*m - n;
        y=0, t=0;
        vi F;
        int tot_sum = 0;
        for(map<int,int>::iterator it = M.begin();it!= M.end();++it)
            F.pb(it->S) , tot_sum += it->S;
        int d = sz(F);
        // rep(i,d)
        //     cout<<F[i]<<" ";
        // nl;

        int k = (8*m) / n;
        if(k >= d or k >= 20)
        {
            cout<<"0\n";
            continue;
        }
        int K = 1 << k;

        // pv(k); pv(K);

        rep(i,K)
            t += F[i];
        y = tot_sum - t;
        repp(i,1,d-K+1)
        {
            t = t - F[i-1] + F[i+K-1];
            y = min(y, tot_sum - t);
        }
        cout<<y,nl;

    }

    return 0;
}


#include<bits/stdc++.h>
#define nl              cout<<"\n"
#define sz(x)           (int)((x).size())
#define len(x)          (x).length()
#define all(a)          (a).begin(),(a).end()
#define rep(i,n)        for( int i=0;i<(int)(n);i++)
#define brep(i,n)       for( int i=(n);i>=0;i-- )
#define repp(i,a,b)     for( int i = (a); i < (b); i++ )
#define ll      long long int
#define pb      push_back
#define mp      make_pair
#define F       first
#define S       second
#define vi      vector<int>
#define vll     vector<ll>
#define pii     pair<int,int>
#define vpii    vector<pair<int,int> >
#define bits    __builtin_popcountll
#define mod     1000000007
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define test int tes; cin >> tes; while( tes-- > 0 )
#define pv(x) cout<< #x<< " = "<<(x)<<"\n";
#define foreach(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#ifndef ONLINE_JUDGE
bool ipfile = freopen("ip.txt","r",stdin);
bool opfile = freopen("op.txt","w",stdout);
#endif
using namespace std;
int n,m,x,y,t,q;

double ans,h,l;

int main()
{
    fast
    while(cin>>n>>m)
    {
        map<int,int>M;
        rep(i,n)
            cin>>q , M[q]++;

        x = 8*m - n;

    // pv(x);

        y=0;
        vi A;
        for(map<int,int>::iterator it = M.begin();it!= M.end();++it)
            A.pb(it->S);
        // if( sz(A) <= x )
        // {
        //     cout<<"0\n";
        //     continue;
        // }
        sort(all(A));
        // rep(i,sz(A))
        //     cout<<A[i]<<" ";
        // nl;
        ll d = sz(A);
        ll md = 1<<((8*m + n -1)/n);
        int diff = md - d;
        rep(i,d)
        {
            if((ceil(log2(d-i))*n) <= (8*m))
                break;
            y += A[i];
        }
        cout<<y,nl;
    }

    return 0;
}


#include<bits/stdc++.h>
#define nl              cout<<"\n"
#define sz(x)           (int)((x).size())
#define len(x)          (x).length()
#define all(a)          (a).begin(),(a).end()
#define rep(i,n)        for( int i=0;i<(int)(n);i++)
#define brep(i,n)       for( int i=(n);i>=0;i-- )
#define repp(i,a,b)     for( int i = (a); i < (b); i++ )
#define ll      long long int
#define pb      push_back
#define mp      make_pair
#define F       first
#define S       second
#define vi      vector<int>
#define vll     vector<ll>
#define pii     pair<int,int>
#define vpii    vector<pair<int,int> >
#define bits    __builtin_popcountll
#define mod     1000000007
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define test int tes; cin >> tes; while( tes-- > 0 )
#define pv(x) cout<< #x<< " = "<<(x)<<"\n";
#define foreach(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#ifndef ONLINE_JUDGE
bool ipfile = freopen("ip.txt","r",stdin);
bool opfile = freopen("op.txt","w",stdout);
#endif
using namespace std;
int n,m,x,y,t,q;

double ans,h,l;

int main()
{
    fast
    while(cin>>n>>m)
    {
        map<int,int>M;
        rep(i,n)
            cin>>q , M[q]++;

        x = 8*m - n;

    // pv(x);

        y=0;
        vi A;
        for(map<int,int>::iterator it = M.begin();it!= M.end();++it)
            A.pb(it->S);
        if( sz(A) <= x )
        {
            cout<<"0\n";
            continue;
        }
        sort(all(A));
        // rep(i,sz(A))
        //     cout<<A[i]<<" ";
        // nl;
        rep(i,sz(A))
        {
            y += A[i];
            if((sz(A)-1-i) <= x)
                break;
        }
        cout<<y,nl;
    }

    return 0;
}


#include<bits/stdc++.h>
#define nl              cout<<"\n"
#define sz(x)           (int)((x).size())
#define len(x)          (x).length()
#define all(a)          (a).begin(),(a).end()
#define rep(i,n)        for( int i=0;i<(int)(n);i++)
#define brep(i,n)       for( int i=(n);i>=0;i-- )
#define repp(i,a,b)     for( int i = (a); i < (b); i++ )
#define ll      long long int
#define pb      push_back
#define mp      make_pair
#define F       first
#define S       second
#define vi      vector<int>
#define vll     vector<ll>
#define pii     pair<int,int>
#define vpii    vector<pair<int,int> >
#define bits    __builtin_popcountll
#define mod     1000000007
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define test int tes; cin >> tes; while( tes-- > 0 )
#define pv(x) cout<< #x<< " = "<<(x)<<"\n";
#define foreach(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#ifndef ONLINE_JUDGE
bool ipfile = freopen("ip.txt","r",stdin);
bool opfile = freopen("op.txt","w",stdout);
#endif
using namespace std;
int n,m,x,y,t,q;

double ans,h,l;

int main()
{
    fast
    while(cin>>n>>m)
    {
        map<int,int>M;
        rep(i,n)
            cin>>q , M[q]++;

        x = 8*m - n;

    // pv(x);

        y=0;
        vi A;
        for(map<int,int>::iterator it = M.begin();it!= M.end();++it)
            A.pb(it->S);
        // if( sz(A) <= x )
        // {
        //     cout<<"0\n";
        //     continue;
        // }
        sort(all(A));
        // rep(i,sz(A))
        //     cout<<A[i]<<" ";
        // nl;
        ll d = sz(A);
        ll md = 1<<((8*m + n -1)/n);
        int diff = md - d;
        rep(i,d)
        {
            if(((log2(d-i))*n) <= (8*m))
                break;
            y += A[i];
        }
        cout<<y,nl;
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

const int MOD = 1e9 + 7; // change if needed

struct Modint {
  ll val;

  Modint (ll _val = 0)
    : val(_val % MOD) {}

  Modint operator+ (Modint other) const {
    return Modint(val + other.val);
  }

  void operator+= (Modint other) {
    val += other.val;
    val %= MOD;
  }

  Modint operator- () const {
    return Modint(MOD - val);
  }

  Modint operator- (Modint other) const {
    return Modint(val + MOD - other.val);
  }

  void operator-= (Modint other) {
    val += MOD - other.val;
    val %= MOD;
  }

  Modint operator* (Modint other) const {
    return Modint(val * other.val);
  }

  void operator*= (Modint other) {
    val *= other.val;
    val %= MOD;
  }

  bool operator== (Modint other) const {
    return val == other.val;
  }

  bool operator!= (Modint other) const {
    return val != other.val;
  }
};

Modint exp (Modint a, int k) {
  if (k == 0) {
    return Modint(1);
  } else if (k % 2 == 0) {
    Modint half = exp(a, k / 2);
    return half * half;
  } else {
    return a * exp(a, k - 1);
  }
}

Modint inv (Modint a) {
  return exp(a, MOD - 2);
}

ostream& operator<< (ostream& out, Modint p) {
  out << p.val;
  return out;
}

const int MAX_N = 1e5 + 5;

vector<int> adj [MAX_N];
Modint dp [MAX_N][2];

void dfs (int u) {
  for (int nxt : adj[u]) {
    dfs(nxt);
  }

  for (int k = 0; k < 2; k++) {
    vector<Modint> cnt = {Modint(0), Modint(1)};
    for (int nxt : adj[u]) {
      vector<Modint> add = {cnt[0] * dp[nxt][0] + cnt[1] * dp[nxt][1],
                            cnt[1] * dp[nxt][0] + cnt[0] * dp[nxt][1]};
      cnt[0] += add[0];
      cnt[1] += add[1];
    }

    dp[u][0] += cnt[0];
    dp[u][1] += cnt[1];

    reverse(adj[u].begin(), adj[u].end());
  }

  // both-ways
  {
    Modint allz = Modint(1);
    vector<Modint> allo = {Modint(0), Modint(1)};

    for (int nxt : adj[u]) {
      allz += allz * dp[nxt][0];
      vector<Modint> add = {allo[1] * dp[nxt][1], allo[0] * dp[nxt][1]};
      allo[0] += add[0];
      allo[1] += add[1];
    }

    dp[u][1] -= allz;
    dp[u][0] -= allo[0];
  }
}

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

  int n;
  cin >> n;

  for (int i = 2; i <= n; i++) {
    int p;
    cin >> p;

    adj[p].push_back(i);
  }

  dfs(1);

  cout << dp[1][0] + dp[1][1] << endl;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef tuple<int, int, int> tiii;
typedef tuple<int, int, int, int> tiiii;
typedef set <int> si;
typedef map <int, int> mii;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <vector <int>> vvi;
typedef vector<pii> vpii;
#define F(i, a, b) for(int i = (int)a; i <= (int)b; i++)
#define f(i, a, b) for(int i = (int)a; i >= (int)b; i--)
#define F2(i, a, b) for(int i = (int)a; i <= (int)b; i+=2)
#define f2(i, a, b) for(int i = (int)a; i >= (int)b; i-=2)
#define wh(n) int iteration = n; while(iteration--)
#define For(t, it) for(auto it = (t).begin(); it != (t).end(); ++it)
#define IN insert
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define RS resize
#define uset unordered_set
#define umap unordered_map
#define RBT tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ld const PI = acos(-1);

int const mod = 1e9 + 7, N = 1e5 + 4;
int sum(int a, int b){
	a += b;
	return (a >= mod ? a-mod : a);
}
int sub(int a, int b){
	a -= b;
	return (a < 0 ? a+mod : a);
}
int mlt(int a, int b){
	return (a*1ll*b)%mod;
}

int dp[N][2]; //dp[vertex][parity of delta_cnt]
int cdp[2], ndp[2], id[2][2], nid[2][2];      //id[after last][pre rev last]
list<int> gr[N];

void DP(int v){
	for(int to : gr[v])
		DP(to);
	F(i, 0, 1){
		cdp[i] = i;
		F(j, 0, 1)
			id[i][j] = i;
	}
	for(int u : gr[v]){
		F(c, 0, 1)
			ndp[c] = sum(mlt(cdp[c], sum(dp[u][0], 1)), mlt(cdp[!c], dp[u][1]));
	       	F(c, 0, 1)
	       		cdp[c] = ndp[c];
		F(plc, 0, 1)
			F(rc, 0, 1){
				nid[plc][rc] = sum(nid[plc][rc], id[plc][rc]);
				if(plc == rc)
					F(dc, 0, 1)
						nid[plc^dc][rc] = sum(nid[plc^dc][rc], mlt(id[plc][rc^dc], dp[u][dc]));
			}
		F(i, 0, 1){
			cdp[i] = ndp[i];
			ndp[i] = 0;
			F(j, 0, 1){
				id[i][j] = nid[i][j];
				nid[i][j] = 0;
			//	cerr << id[i][j] << ' ';
			}
			//cerr << '\n';
		}
		//cerr << '\n';
	}
	F(i, 0, 1){
		dp[v][i] = sub(cdp[i], id[i][1]);
		cdp[i] = i;
	}
	reverse(gr[v].begin(), gr[v].end());
	for(int u : gr[v]){
		F(c, 0, 1)
			ndp[c] = sum(mlt(cdp[c], sum(dp[u][0], 1)), mlt(cdp[!c], dp[u][1]));
	       	F(i, 0, 1){
			cdp[i] = ndp[i];
			ndp[i] = 0;
		}
	}
	F(i, 0, 1)
		dp[v][i] = sum(dp[v][i], cdp[i]);
}

//#define LOCAL
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
        #ifdef LOCAL
        freopen("in", "r", stdin);
        freopen("out", "w", stdout);
        #endif
	int n, p;
	cin >> n;
	F(i, 2, n){
		cin >> p;
		gr[p].PB(i);
	}
	DP(1);
	cout << sum(dp[1][0], dp[1][1]);
	return 0;
}


#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define mt make_tuple
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tiii;
const ll mod = 1e9+7;

vector<int> children[100007];
ll odd[100007], even[100007];
int N;

int main(){
    scanf("%d", &N);
    for(int i = 2; i <= N; i++){
        int p;
        scanf("%d", &p);
        children[p].pb(i);
    }
    for(int i = N; i >= 1; i--){
        ll o = 0, e = 1ll, ao = 0, ae = 1ll, ev = 1ll;
        for(auto j : children[i]){
            ll o2 = odd[j] * e + even[j] * o;
            ll e2 = odd[j] * o + even[j] * e;
            ll ao2 = ao + odd[j] * ae;
            ll ae2 = ae + odd[j] * ao;
            ev *= even[j];
            o = o2 % mod;
            e = e2 % mod;
            ao = ao2 % mod;
            ae = ae2 % mod;
            ev %= mod;
        }
        e *= 2ll;
        e -= ev;
        e += mod;
        e %= mod;
        o *= 2ll;
        o -= ao;
        o += mod;
        o %= mod;
        odd[i] = e;
        even[i] = (o + 1ll) % mod;
        //cout << i << ' ' << even[i] << ' ' << odd[i] << endl;
    }
    printf("%lld\n", (odd[1] + even[1] - 1ll + mod) % mod);
    return 0;
}


#include "bits/stdc++.h"
using namespace std;
#ifndef LOCAL
#define endl '\n'
#endif

#define fr(i, a, b) for(int i = a; i <= b; i++)
#define rf(i, a, b) for(int i = a; i >= b; i--)
#define pf push_front
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
#define rsz resize()
#define lb lower_bound
#define ub upper_bound
#define br cout << endl

typedef long long ll;
typedef long double f80;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int pct(int x) { return __builtin_popcount(x); }
int pct(ll x) { return __builtin_popcountll(x); }
int bit(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))
int bit(ll x) { return 63 - __builtin_clzll(x); } // floor(log2(x))
int cdiv(int a, int b) { return a / b + !(a < 0 || a % b == 0); }
ll cdiv(ll a, ll b) { return a / b + !(a < 0 || a % b == 0); }

template<typename T>
void leftShift(vector<T> &v, ll k) { k %= sz(v); if(k < 0) k += sz(v); rotate(v.begin(), v.begin() + k, v.end()); }
template<typename T>
void rightSift(vector<T> &v, ll k) { leftShift(v, sz(v) - k); }

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll rand(ll l, ll r){
	uniform_int_distribution<ll> uid(l, r);
	return uid(rng);
}

inline int nxt() {
	int x;
	cin >> x;
	return x;
}

inline int nxtll() {
	ll x;
	cin >> x;
	return x;
}

void pr() {}
void sc() {}

template <typename Head, typename... Tail>
void pr(Head H, Tail... T) { cout << H << " "; pr(T...); }

template <typename Head, typename... Tail>
void sc(Head &H, Tail &... T) { cin >> H; sc(T...); }

#ifdef LOCAL
#define debug(...) cerr << "[L:" << __LINE__ << "][" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#ifndef LOCAL
string to_string(__int128 x) {
	string s = "";
	bool neg = 0;
	if(x < 0) { s += "-"; neg = 1; }
	if(!x) s += '0';
	while(x) {
		int rem = x % 10;
		s += to_string(rem);
		x /= 10;
	}
	reverse(s.begin() + neg, s.end());
	return s;
}
#endif

const int mod = 1e9 + 7; // 998244353;

int pwr(int a,int b) {
	int ans = 1;
	while(b) {
		if(b & 1) ans = (ans * 1LL * a) % mod;
		a = (a * 1LL * a) % mod;
		b >>= 1;
	}
	return ans;
}

/*
	Lookout for overflows!!
	Check array sizes!!
	Clear before test cases!!
	Use the correct modulo!!
	Check for corner cases!!
	Are you forgetting something?!
*/

template <typename T>
T inverse(T a, T m) {
  T u = 0, v = 1;
  while (a != 0) {
    T t = m / a;
    m -= t * a; swap(a, m);
    u -= t * v; swap(u, v);
  }
  assert(m == 1);
  return u;
}

template <typename T>
class Modular {
 public:
  using Type = typename decay<decltype(T::value)>::type;

  constexpr Modular() : value() {}
  template <typename U>
  Modular(const U& x) {
    value = normalize(x);
  }

  template <typename U>
  static Type normalize(const U& x) {
    Type v;
    if (-mod() <= x && x < mod()) v = static_cast<Type>(x);
    else v = static_cast<Type>(x % mod());
    if (v < 0) v += mod();
    return v;
  }

  const Type& operator()() const { return value; }
  template <typename U>
  explicit operator U() const { return static_cast<U>(value); }
  constexpr static Type mod() { return T::value; }

  Modular& operator+=(const Modular& other) { if ((value += other.value) >= mod()) value -= mod(); return *this; }
  Modular& operator-=(const Modular& other) { if ((value -= other.value) < 0) value += mod(); return *this; }
  template <typename U> Modular& operator+=(const U& other) { return *this += Modular(other); }
  template <typename U> Modular& operator-=(const U& other) { return *this -= Modular(other); }
  Modular& operator++() { return *this += 1; }
  Modular& operator--() { return *this -= 1; }
  Modular operator++(int) { Modular result(*this); *this += 1; return result; }
  Modular operator--(int) { Modular result(*this); *this -= 1; return result; }
  Modular operator-() const { return Modular(-value); }

  template <typename U = T>
  typename enable_if<is_same<typename Modular<U>::Type, int>::value, Modular>::type& operator*=(const Modular& rhs) {
#ifdef _WIN32
    uint64_t x = static_cast<int64_t>(value) * static_cast<int64_t>(rhs.value);
    uint32_t xh = static_cast<uint32_t>(x >> 32), xl = static_cast<uint32_t>(x), d, m;
    asm(
      "divl %4; \n\t"
      : "=a" (d), "=d" (m)
      : "d" (xh), "a" (xl), "r" (mod())
    );
    value = m;
#else
    value = normalize(static_cast<int64_t>(value) * static_cast<int64_t>(rhs.value));
#endif
    return *this;
  }
  template <typename U = T>
  typename enable_if<is_same<typename Modular<U>::Type, int64_t>::value, Modular>::type& operator*=(const Modular& rhs) {
    int64_t q = static_cast<int64_t>(static_cast<long double>(value) * rhs.value / mod());
    value = normalize(value * rhs.value - q * mod());
    return *this;
  }
  template <typename U = T>
  typename enable_if<!is_integral<typename Modular<U>::Type>::value, Modular>::type& operator*=(const Modular& rhs) {
    value = normalize(value * rhs.value);
    return *this;
  }

  Modular& operator/=(const Modular& other) { return *this *= Modular(inverse(other.value, mod())); }

  template <typename U>
  friend const Modular<U>& abs(const Modular<U>& v) { return v; }

  template <typename U>
  friend bool operator==(const Modular<U>& lhs, const Modular<U>& rhs);

  template <typename U>
  friend bool operator<(const Modular<U>& lhs, const Modular<U>& rhs);

  template <typename U>
  friend std::istream& operator>>(std::istream& stream, Modular<U>& number);

 private:
  Type value;
};

template <typename T> bool operator==(const Modular<T>& lhs, const Modular<T>& rhs) { return lhs.value == rhs.value; }
template <typename T, typename U> bool operator==(const Modular<T>& lhs, U rhs) { return lhs == Modular<T>(rhs); }
template <typename T, typename U> bool operator==(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) == rhs; }

template <typename T> bool operator!=(const Modular<T>& lhs, const Modular<T>& rhs) { return !(lhs == rhs); }
template <typename T, typename U> bool operator!=(const Modular<T>& lhs, U rhs) { return !(lhs == rhs); }
template <typename T, typename U> bool operator!=(U lhs, const Modular<T>& rhs) { return !(lhs == rhs); }

template <typename T> bool operator<(const Modular<T>& lhs, const Modular<T>& rhs) { return lhs.value < rhs.value; }

template <typename T> Modular<T> operator+(const Modular<T>& lhs, const Modular<T>& rhs) { return Modular<T>(lhs) += rhs; }
template <typename T, typename U> Modular<T> operator+(const Modular<T>& lhs, U rhs) { return Modular<T>(lhs) += rhs; }
template <typename T, typename U> Modular<T> operator+(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) += rhs; }

template <typename T> Modular<T> operator-(const Modular<T>& lhs, const Modular<T>& rhs) { return Modular<T>(lhs) -= rhs; }
template <typename T, typename U> Modular<T> operator-(const Modular<T>& lhs, U rhs) { return Modular<T>(lhs) -= rhs; }
template <typename T, typename U> Modular<T> operator-(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) -= rhs; }

template <typename T> Modular<T> operator*(const Modular<T>& lhs, const Modular<T>& rhs) { return Modular<T>(lhs) *= rhs; }
template <typename T, typename U> Modular<T> operator*(const Modular<T>& lhs, U rhs) { return Modular<T>(lhs) *= rhs; }
template <typename T, typename U> Modular<T> operator*(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) *= rhs; }

template <typename T> Modular<T> operator/(const Modular<T>& lhs, const Modular<T>& rhs) { return Modular<T>(lhs) /= rhs; }
template <typename T, typename U> Modular<T> operator/(const Modular<T>& lhs, U rhs) { return Modular<T>(lhs) /= rhs; }
template <typename T, typename U> Modular<T> operator/(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) /= rhs; }

template<typename T, typename U>
Modular<T> power(const Modular<T>& a, const U& b) {
  assert(b >= 0);
  Modular<T> x = a, res = 1;
  U p = b;
  while (p > 0) {
    if (p & 1) res *= x;
    x *= x;
    p >>= 1;
  }
  return res;
}

template <typename T>
bool IsZero(const Modular<T>& number) {
  return number() == 0;
}

template <typename T>
string to_string(const Modular<T>& number) {
  return to_string(number());
}

template <typename T>
std::ostream& operator<<(std::ostream& stream, const Modular<T>& number) {
  return stream << number();
}

template <typename T>
std::istream& operator>>(std::istream& stream, Modular<T>& number) {
  typename common_type<typename Modular<T>::Type, int64_t>::type x;
  stream >> x;
  number.value = Modular<T>::normalize(x);
  return stream;
}

/*
using ModType = int;

struct VarMod { static ModType value; };
ModType VarMod::value;
ModType& md = VarMod::value;
using Mint = Modular<VarMod>;
*/

constexpr int md = 1e9 + 7;
using Mint = Modular<std::integral_constant<decay<decltype(md)>::type, md>>;

const int N = 1e5 + 5;
vector<int> g[N];
Mint dp[N][2][2];
Mint dp1[2][2][3], dp2[2][2][3];

void dfs(int u,int p) {
	sort(all(g[u]));
	for(int v : g[u]) {
		if(v != p) {
			dfs(v, u);
		}
	}
	memset(dp1, 0, sizeof dp1);
	dp1[1][0][2] = 1;
	dp1[0][1][2] = 1;
	for(int v : g[u]) {
		if(v != p) {
			memset(dp2, 0, sizeof dp2);
			fr(i, 0, 1) {
				fr(j, 0, 1) {
					fr(k, 0, 2) {
						if(!dp1[i][j][k]) continue;
						// rnd = 1
						dp2[i][j][k] += dp1[i][j][k];
						// rnd = 0
						fr(l, 0, 1) { // finishing at l
							dp2[i][l][j] += dp1[i][j][k] * dp[v][j][l];
						}
					}
				}
			}
			fr(i, 0, 1) {
				fr(j, 0, 1) {
					fr(k, 0, 2) {
						dp1[i][j][k] = dp2[i][j][k];
					}
				}
			}
		}
	}
	fr(i, 0, 1) {
		fr(j, 0, 1) {
			fr(k, 0, 2) {
				dp[u][i][j] += dp1[i][j][k];
			}
		}
	}
	reverse(all(g[u]));
	memset(dp1, 0, sizeof dp1);
	dp1[1][0][2] = 1;
	dp1[0][1][2] = 1;
	for(int v : g[u]) {
		if(v != p) {
			memset(dp2, 0, sizeof dp2);
			fr(i, 0, 1) {
				fr(j, 0, 1) {
					fr(k, 0, 2) {
						if(!dp1[i][j][k]) continue;
						// rnd = 1
						dp2[i][j][k] += dp1[i][j][k];
						// rnd = 0
						fr(l, 0, 1) { // finishing at l
							dp2[i][l][j] += dp1[i][j][k] * dp[v][j][l];
						}
					}
				}
			}
			fr(i, 0, 1) {
				fr(j, 0, 1) {
					fr(k, 0, 2) {
						dp1[i][j][k] = dp2[i][j][k];
					}
				}
			}
		}
	}
	fr(i, 0, 1) {
		fr(j, 0, 1) {
			dp[u][i][j] += dp1[i][j][i];
		}
	}
	// fr(i, 0, 1) {
	// 	fr(j, 0, 1) {
	// 		if(dp[u][i][j])
	// 			debug(u, i, j, dp[u][i][j]);
	// 	}
	// }
}

void solve() {
	int n = nxt();
	fr(i, 2, n) {
		g[nxt()].pb(i);
	}
	dfs(1, 0);
	Mint ans = dp[1][0][0] + dp[1][0][1];
	cout << ans;
}

signed main() {
	ios :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	// cin >> t;
	t = 1;
	for(int tt = 1; tt <= t; tt++) {
		solve();
	}
	return 0;
}


#include "bits/stdc++.h"
using namespace std;
#ifndef LOCAL
#define endl '\n'
#endif

#define fr(i, a, b) for(int i = a; i <= b; i++)
#define rf(i, a, b) for(int i = a; i >= b; i--)
#define pf push_front
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
#define rsz resize()
#define lb lower_bound
#define ub upper_bound
#define br cout << endl

typedef long long ll;
typedef long double f80;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int pct(int x) { return __builtin_popcount(x); }
int pct(ll x) { return __builtin_popcountll(x); }
int bit(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))
int bit(ll x) { return 63 - __builtin_clzll(x); } // floor(log2(x))
int cdiv(int a, int b) { return a / b + !(a < 0 || a % b == 0); }
ll cdiv(ll a, ll b) { return a / b + !(a < 0 || a % b == 0); }

template<typename T>
void leftShift(vector<T> &v, ll k) { k %= sz(v); if(k < 0) k += sz(v); rotate(v.begin(), v.begin() + k, v.end()); }
template<typename T>
void rightSift(vector<T> &v, ll k) { leftShift(v, sz(v) - k); }

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll rand(ll l, ll r){
	uniform_int_distribution<ll> uid(l, r);
	return uid(rng);
}

inline int nxt() {
	int x;
	cin >> x;
	return x;
}

inline ll nxtll() {
	ll x;
	cin >> x;
	return x;
}

void pr() {}
void sc() {}

template <typename Head, typename... Tail>
void pr(Head H, Tail... T) { cout << H << " "; pr(T...); }

template <typename Head, typename... Tail>
void sc(Head &H, Tail &... T) { cin >> H; sc(T...); }

#ifdef LOCAL
#define debug(...) cerr << "[L:" << __LINE__ << "][" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#ifndef LOCAL
string to_string(__int128 x) {
	string s = "";
	bool neg = 0;
	if(x < 0) { s += "-"; neg = 1; }
	if(!x) s += '0';
	while(x) {
		int rem = x % 10;
		s += to_string(rem);
		x /= 10;
	}
	reverse(s.begin() + neg, s.end());
	return s;
}
#endif

const int mod = 1e9 + 7; // 998244353;

int pwr(int a,int b) {
	int ans = 1;
	while(b) {
		if(b & 1) ans = (ans * 1LL * a) % mod;
		a = (a * 1LL * a) % mod;
		b >>= 1;
	}
	return ans;
}

/*
	Lookout for overflows!!
	Check array sizes!!
	Clear before test cases!!
	Use the correct modulo!!
	Check for corner cases!!
	Are you forgetting something?!
*/

template <typename T>
T inverse(T a, T m) {
  T u = 0, v = 1;
  while (a != 0) {
    T t = m / a;
    m -= t * a; swap(a, m);
    u -= t * v; swap(u, v);
  }
  assert(m == 1);
  return u;
}

template <typename T>
class Modular {
 public:
  using Type = typename decay<decltype(T::value)>::type;

  constexpr Modular() : value() {}
  template <typename U>
  Modular(const U& x) {
    value = normalize(x);
  }

  template <typename U>
  static Type normalize(const U& x) {
    Type v;
    if (-mod() <= x && x < mod()) v = static_cast<Type>(x);
    else v = static_cast<Type>(x % mod());
    if (v < 0) v += mod();
    return v;
  }

  const Type& operator()() const { return value; }
  template <typename U>
  explicit operator U() const { return static_cast<U>(value); }
  constexpr static Type mod() { return T::value; }

  Modular& operator+=(const Modular& other) { if ((value += other.value) >= mod()) value -= mod(); return *this; }
  Modular& operator-=(const Modular& other) { if ((value -= other.value) < 0) value += mod(); return *this; }
  template <typename U> Modular& operator+=(const U& other) { return *this += Modular(other); }
  template <typename U> Modular& operator-=(const U& other) { return *this -= Modular(other); }
  Modular& operator++() { return *this += 1; }
  Modular& operator--() { return *this -= 1; }
  Modular operator++(int) { Modular result(*this); *this += 1; return result; }
  Modular operator--(int) { Modular result(*this); *this -= 1; return result; }
  Modular operator-() const { return Modular(-value); }

  template <typename U = T>
  typename enable_if<is_same<typename Modular<U>::Type, int>::value, Modular>::type& operator*=(const Modular& rhs) {
#ifdef _WIN32
    uint64_t x = static_cast<int64_t>(value) * static_cast<int64_t>(rhs.value);
    uint32_t xh = static_cast<uint32_t>(x >> 32), xl = static_cast<uint32_t>(x), d, m;
    asm(
      "divl %4; \n\t"
      : "=a" (d), "=d" (m)
      : "d" (xh), "a" (xl), "r" (mod())
    );
    value = m;
#else
    value = normalize(static_cast<int64_t>(value) * static_cast<int64_t>(rhs.value));
#endif
    return *this;
  }
  template <typename U = T>
  typename enable_if<is_same<typename Modular<U>::Type, int64_t>::value, Modular>::type& operator*=(const Modular& rhs) {
    int64_t q = static_cast<int64_t>(static_cast<long double>(value) * rhs.value / mod());
    value = normalize(value * rhs.value - q * mod());
    return *this;
  }
  template <typename U = T>
  typename enable_if<!is_integral<typename Modular<U>::Type>::value, Modular>::type& operator*=(const Modular& rhs) {
    value = normalize(value * rhs.value);
    return *this;
  }

  Modular& operator/=(const Modular& other) { return *this *= Modular(inverse(other.value, mod())); }

  template <typename U>
  friend const Modular<U>& abs(const Modular<U>& v) { return v; }

  template <typename U>
  friend bool operator==(const Modular<U>& lhs, const Modular<U>& rhs);

  template <typename U>
  friend bool operator<(const Modular<U>& lhs, const Modular<U>& rhs);

  template <typename U>
  friend std::istream& operator>>(std::istream& stream, Modular<U>& number);

 private:
  Type value;
};

template <typename T> bool operator==(const Modular<T>& lhs, const Modular<T>& rhs) { return lhs.value == rhs.value; }
template <typename T, typename U> bool operator==(const Modular<T>& lhs, U rhs) { return lhs == Modular<T>(rhs); }
template <typename T, typename U> bool operator==(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) == rhs; }

template <typename T> bool operator!=(const Modular<T>& lhs, const Modular<T>& rhs) { return !(lhs == rhs); }
template <typename T, typename U> bool operator!=(const Modular<T>& lhs, U rhs) { return !(lhs == rhs); }
template <typename T, typename U> bool operator!=(U lhs, const Modular<T>& rhs) { return !(lhs == rhs); }

template <typename T> bool operator<(const Modular<T>& lhs, const Modular<T>& rhs) { return lhs.value < rhs.value; }

template <typename T> Modular<T> operator+(const Modular<T>& lhs, const Modular<T>& rhs) { return Modular<T>(lhs) += rhs; }
template <typename T, typename U> Modular<T> operator+(const Modular<T>& lhs, U rhs) { return Modular<T>(lhs) += rhs; }
template <typename T, typename U> Modular<T> operator+(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) += rhs; }

template <typename T> Modular<T> operator-(const Modular<T>& lhs, const Modular<T>& rhs) { return Modular<T>(lhs) -= rhs; }
template <typename T, typename U> Modular<T> operator-(const Modular<T>& lhs, U rhs) { return Modular<T>(lhs) -= rhs; }
template <typename T, typename U> Modular<T> operator-(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) -= rhs; }

template <typename T> Modular<T> operator*(const Modular<T>& lhs, const Modular<T>& rhs) { return Modular<T>(lhs) *= rhs; }
template <typename T, typename U> Modular<T> operator*(const Modular<T>& lhs, U rhs) { return Modular<T>(lhs) *= rhs; }
template <typename T, typename U> Modular<T> operator*(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) *= rhs; }

template <typename T> Modular<T> operator/(const Modular<T>& lhs, const Modular<T>& rhs) { return Modular<T>(lhs) /= rhs; }
template <typename T, typename U> Modular<T> operator/(const Modular<T>& lhs, U rhs) { return Modular<T>(lhs) /= rhs; }
template <typename T, typename U> Modular<T> operator/(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) /= rhs; }

template<typename T, typename U>
Modular<T> power(const Modular<T>& a, const U& b) {
  assert(b >= 0);
  Modular<T> x = a, res = 1;
  U p = b;
  while (p > 0) {
    if (p & 1) res *= x;
    x *= x;
    p >>= 1;
  }
  return res;
}

template <typename T>
bool IsZero(const Modular<T>& number) {
  return number() == 0;
}

template <typename T>
string to_string(const Modular<T>& number) {
  return to_string(number());
}

template <typename T>
std::ostream& operator<<(std::ostream& stream, const Modular<T>& number) {
  return stream << number();
}

template <typename T>
std::istream& operator>>(std::istream& stream, Modular<T>& number) {
  typename common_type<typename Modular<T>::Type, int64_t>::type x;
  stream >> x;
  number.value = Modular<T>::normalize(x);
  return stream;
}

/*
using ModType = int;

struct VarMod { static ModType value; };
ModType VarMod::value;
ModType& md = VarMod::value;
using Mint = Modular<VarMod>;
*/

constexpr int md = 1e9 + 7;
using Mint = Modular<std::integral_constant<decay<decltype(md)>::type, md>>;

const int N = 1e5 + 5;
vector<int> g[N];
Mint dp[N][2];
Mint dp1[2][2][2]; // dp[u][parity of count of odd subtrees][if even taken][if odd taken]
Mint dp2[2][2][2];

void dfs(int u) {
	for(int v : g[u]) {
		dfs(v);
	}
	memset(dp1, 0, sizeof dp1);
	dp1[0][0][0] = 1;
	for(int v : g[u]) {
		memset(dp2, 0, sizeof dp2);
		fr(b1, 0, 1) {
			fr(b2, 0, 1) {
				fr(b3, 0, 1) {
					if(!dp1[b1][b2][b3]) continue;
					fr(p, 0, 1) { // take even, take odd
						dp2[b1 ^ p][b2 | (p == 0)][b3 | (p == 1)] += dp1[b1][b2][b3] * dp[v][p];
					}
					// don't take
					dp2[b1][b2][b3] += dp1[b1][b2][b3];
				}
			}
		}
		fr(b1, 0, 1) {
			fr(b2, 0, 1) {
				fr(b3, 0, 1) {
					dp1[b1][b2][b3] = dp2[b1][b2][b3];
				}
			}
		}
	}
	fr(b1, 0, 1) {
		fr(b2, 0, 1) {
			fr(b3, 0, 1) {
				if(!dp1[b1][b2][b3]) continue;
				Mint mul = 2;
				if(b2 == 0 && b3 == 0) mul = 1;
				else if(!b2 && (b1 == 1)) mul = 1;
				else if(!b3) mul = 1;
				if(u == 1)
					debug(b1, b2, b3, dp1[b1][b2][b3], mul);
				dp[u][b1 ^ 1] += mul * dp1[b1][b2][b3];
			}
		}
	}
	fr(i, 0, 1) {
		debug(u, i, dp[u][i]);
	}
}

void solve() {
	int n = nxt();
	fr(i, 2, n) {
		g[nxt()].pb(i);
	}
	dfs(1);
	Mint ans = dp[1][0] + dp[1][1];
	cout << ans;
}

signed main() {
	ios :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	// cin >> t;
	t = 1;
	for(int tt = 1; tt <= t; tt++) {
		solve();
	}
	return 0;
}


#include "bits/stdc++.h"
using namespace std;
#ifndef LOCAL
#define endl '\n'
#endif

#define fr(i, a, b) for(int i = a; i <= b; i++)
#define rf(i, a, b) for(int i = a; i >= b; i--)
#define pf push_front
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
#define rsz resize()
#define lb lower_bound
#define ub upper_bound
#define br cout << endl

typedef long long ll;
typedef long double f80;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int pct(int x) { return __builtin_popcount(x); }
int pct(ll x) { return __builtin_popcountll(x); }
int bit(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))
int bit(ll x) { return 63 - __builtin_clzll(x); } // floor(log2(x))
int cdiv(int a, int b) { return a / b + !(a < 0 || a % b == 0); }
ll cdiv(ll a, ll b) { return a / b + !(a < 0 || a % b == 0); }

template<typename T>
void leftShift(vector<T> &v, ll k) { k %= sz(v); if(k < 0) k += sz(v); rotate(v.begin(), v.begin() + k, v.end()); }
template<typename T>
void rightSift(vector<T> &v, ll k) { leftShift(v, sz(v) - k); }

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll rand(ll l, ll r){
	uniform_int_distribution<ll> uid(l, r);
	return uid(rng);
}

inline int nxt() {
	int x;
	cin >> x;
	return x;
}

inline int nxtll() {
	ll x;
	cin >> x;
	return x;
}

void pr() {}
void sc() {}

template <typename Head, typename... Tail>
void pr(Head H, Tail... T) { cout << H << " "; pr(T...); }

template <typename Head, typename... Tail>
void sc(Head &H, Tail &... T) { cin >> H; sc(T...); }

#ifdef LOCAL
#define debug(...) cerr << "[L:" << __LINE__ << "][" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#ifndef LOCAL
string to_string(__int128 x) {
	string s = "";
	bool neg = 0;
	if(x < 0) { s += "-"; neg = 1; }
	if(!x) s += '0';
	while(x) {
		int rem = x % 10;
		s += to_string(rem);
		x /= 10;
	}
	reverse(s.begin() + neg, s.end());
	return s;
}
#endif

const int mod = 1e9 + 7; // 998244353;

int pwr(int a,int b) {
	int ans = 1;
	while(b) {
		if(b & 1) ans = (ans * 1LL * a) % mod;
		a = (a * 1LL * a) % mod;
		b >>= 1;
	}
	return ans;
}

/*
	Lookout for overflows!!
	Check array sizes!!
	Clear before test cases!!
	Use the correct modulo!!
	Check for corner cases!!
	Are you forgetting something?!
*/

template <typename T>
T inverse(T a, T m) {
  T u = 0, v = 1;
  while (a != 0) {
    T t = m / a;
    m -= t * a; swap(a, m);
    u -= t * v; swap(u, v);
  }
  assert(m == 1);
  return u;
}

template <typename T>
class Modular {
 public:
  using Type = typename decay<decltype(T::value)>::type;

  constexpr Modular() : value() {}
  template <typename U>
  Modular(const U& x) {
    value = normalize(x);
  }

  template <typename U>
  static Type normalize(const U& x) {
    Type v;
    if (-mod() <= x && x < mod()) v = static_cast<Type>(x);
    else v = static_cast<Type>(x % mod());
    if (v < 0) v += mod();
    return v;
  }

  const Type& operator()() const { return value; }
  template <typename U>
  explicit operator U() const { return static_cast<U>(value); }
  constexpr static Type mod() { return T::value; }

  Modular& operator+=(const Modular& other) { if ((value += other.value) >= mod()) value -= mod(); return *this; }
  Modular& operator-=(const Modular& other) { if ((value -= other.value) < 0) value += mod(); return *this; }
  template <typename U> Modular& operator+=(const U& other) { return *this += Modular(other); }
  template <typename U> Modular& operator-=(const U& other) { return *this -= Modular(other); }
  Modular& operator++() { return *this += 1; }
  Modular& operator--() { return *this -= 1; }
  Modular operator++(int) { Modular result(*this); *this += 1; return result; }
  Modular operator--(int) { Modular result(*this); *this -= 1; return result; }
  Modular operator-() const { return Modular(-value); }

  template <typename U = T>
  typename enable_if<is_same<typename Modular<U>::Type, int>::value, Modular>::type& operator*=(const Modular& rhs) {
#ifdef _WIN32
    uint64_t x = static_cast<int64_t>(value) * static_cast<int64_t>(rhs.value);
    uint32_t xh = static_cast<uint32_t>(x >> 32), xl = static_cast<uint32_t>(x), d, m;
    asm(
      "divl %4; \n\t"
      : "=a" (d), "=d" (m)
      : "d" (xh), "a" (xl), "r" (mod())
    );
    value = m;
#else
    value = normalize(static_cast<int64_t>(value) * static_cast<int64_t>(rhs.value));
#endif
    return *this;
  }
  template <typename U = T>
  typename enable_if<is_same<typename Modular<U>::Type, int64_t>::value, Modular>::type& operator*=(const Modular& rhs) {
    int64_t q = static_cast<int64_t>(static_cast<long double>(value) * rhs.value / mod());
    value = normalize(value * rhs.value - q * mod());
    return *this;
  }
  template <typename U = T>
  typename enable_if<!is_integral<typename Modular<U>::Type>::value, Modular>::type& operator*=(const Modular& rhs) {
    value = normalize(value * rhs.value);
    return *this;
  }

  Modular& operator/=(const Modular& other) { return *this *= Modular(inverse(other.value, mod())); }

  template <typename U>
  friend const Modular<U>& abs(const Modular<U>& v) { return v; }

  template <typename U>
  friend bool operator==(const Modular<U>& lhs, const Modular<U>& rhs);

  template <typename U>
  friend bool operator<(const Modular<U>& lhs, const Modular<U>& rhs);

  template <typename U>
  friend std::istream& operator>>(std::istream& stream, Modular<U>& number);

 private:
  Type value;
};

template <typename T> bool operator==(const Modular<T>& lhs, const Modular<T>& rhs) { return lhs.value == rhs.value; }
template <typename T, typename U> bool operator==(const Modular<T>& lhs, U rhs) { return lhs == Modular<T>(rhs); }
template <typename T, typename U> bool operator==(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) == rhs; }

template <typename T> bool operator!=(const Modular<T>& lhs, const Modular<T>& rhs) { return !(lhs == rhs); }
template <typename T, typename U> bool operator!=(const Modular<T>& lhs, U rhs) { return !(lhs == rhs); }
template <typename T, typename U> bool operator!=(U lhs, const Modular<T>& rhs) { return !(lhs == rhs); }

template <typename T> bool operator<(const Modular<T>& lhs, const Modular<T>& rhs) { return lhs.value < rhs.value; }

template <typename T> Modular<T> operator+(const Modular<T>& lhs, const Modular<T>& rhs) { return Modular<T>(lhs) += rhs; }
template <typename T, typename U> Modular<T> operator+(const Modular<T>& lhs, U rhs) { return Modular<T>(lhs) += rhs; }
template <typename T, typename U> Modular<T> operator+(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) += rhs; }

template <typename T> Modular<T> operator-(const Modular<T>& lhs, const Modular<T>& rhs) { return Modular<T>(lhs) -= rhs; }
template <typename T, typename U> Modular<T> operator-(const Modular<T>& lhs, U rhs) { return Modular<T>(lhs) -= rhs; }
template <typename T, typename U> Modular<T> operator-(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) -= rhs; }

template <typename T> Modular<T> operator*(const Modular<T>& lhs, const Modular<T>& rhs) { return Modular<T>(lhs) *= rhs; }
template <typename T, typename U> Modular<T> operator*(const Modular<T>& lhs, U rhs) { return Modular<T>(lhs) *= rhs; }
template <typename T, typename U> Modular<T> operator*(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) *= rhs; }

template <typename T> Modular<T> operator/(const Modular<T>& lhs, const Modular<T>& rhs) { return Modular<T>(lhs) /= rhs; }
template <typename T, typename U> Modular<T> operator/(const Modular<T>& lhs, U rhs) { return Modular<T>(lhs) /= rhs; }
template <typename T, typename U> Modular<T> operator/(U lhs, const Modular<T>& rhs) { return Modular<T>(lhs) /= rhs; }

template<typename T, typename U>
Modular<T> power(const Modular<T>& a, const U& b) {
  assert(b >= 0);
  Modular<T> x = a, res = 1;
  U p = b;
  while (p > 0) {
    if (p & 1) res *= x;
    x *= x;
    p >>= 1;
  }
  return res;
}

template <typename T>
bool IsZero(const Modular<T>& number) {
  return number() == 0;
}

template <typename T>
string to_string(const Modular<T>& number) {
  return to_string(number());
}

template <typename T>
std::ostream& operator<<(std::ostream& stream, const Modular<T>& number) {
  return stream << number();
}

template <typename T>
std::istream& operator>>(std::istream& stream, Modular<T>& number) {
  typename common_type<typename Modular<T>::Type, int64_t>::type x;
  stream >> x;
  number.value = Modular<T>::normalize(x);
  return stream;
}

/*
using ModType = int;

struct VarMod { static ModType value; };
ModType VarMod::value;
ModType& md = VarMod::value;
using Mint = Modular<VarMod>;
*/

constexpr int md = 1e9 + 7;
using Mint = Modular<std::integral_constant<decay<decltype(md)>::type, md>>;

const int N = 1e5 + 5;
vector<int> g[N];
Mint dp[N][2][2];
Mint dp1[2][2][3], dp2[2][2][3];

void dfs(int u,int p) {
	for(int v : g[u]) {
		if(v != p) {
			dfs(v, u);
		}
	}
	memset(dp1, 0, sizeof dp1);
	dp1[1][0][2] = 1;
	dp1[0][1][2] = 1;
	for(int v : g[u]) {
		if(v != p) {
			memset(dp2, 0, sizeof dp2);
			fr(i, 0, 1) {
				fr(j, 0, 1) {
					fr(k, 0, 2) {
						if(!dp1[i][j][k]) continue;
						// rnd = 1
						dp2[i][j][k] += dp1[i][j][k];
						// rnd = 0
						fr(l, 0, 1) { // finishing at l
							dp2[i][l][j] += dp1[i][j][k] * dp[v][j][l];
						}
					}
				}
			}
			fr(i, 0, 1) {
				fr(j, 0, 1) {
					fr(k, 0, 2) {
						dp1[i][j][k] = dp2[i][j][k];
					}
				}
			}
		}
	}
	fr(i, 0, 1) {
		fr(j, 0, 1) {
			fr(k, 0, 2) {
				dp[u][i][j] += dp1[i][j][k];
			}
		}
	}
	reverse(all(g[u]));
	memset(dp1, 0, sizeof dp1);
	dp1[1][0][2] = 1;
	dp1[0][1][2] = 1;
	for(int v : g[u]) {
		if(v != p) {
			memset(dp2, 0, sizeof dp2);
			fr(i, 0, 1) {
				fr(j, 0, 1) {
					fr(k, 0, 2) {
						if(!dp1[i][j][k]) continue;
						// rnd = 1
						dp2[i][j][k] += dp1[i][j][k];
						// rnd = 0
						fr(l, 0, 1) { // finishing at l
							dp2[i][l][j] += dp1[i][j][k] * dp[v][j][l];
						}
					}
				}
			}
			fr(i, 0, 1) {
				fr(j, 0, 1) {
					fr(k, 0, 2) {
						dp1[i][j][k] = dp2[i][j][k];
					}
				}
			}
		}
	}
	fr(i, 0, 1) {
		fr(j, 0, 1) {
			dp[u][i][j] += dp1[i][j][i];
		}
	}
	// fr(i, 0, 1) {
	// 	fr(j, 0, 1) {
	// 		if(dp[u][i][j])
	// 			debug(u, i, j, dp[u][i][j]);
	// 	}
	// }
}

void solve() {
	int n = nxt();
	fr(i, 2, n) {
		g[nxt()].pb(i);
	}
	dfs(1, 0);
	Mint ans = dp[1][0][0] + dp[1][0][1];
	cout << ans;
}

signed main() {
	ios :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	// cin >> t;
	t = 1;
	for(int tt = 1; tt <= t; tt++) {
		solve();
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<climits>
#include<map>
using namespace std;
#define maxn 110000
#define LL __int64
#define mods 1000000007
int n;
vector<int> e[maxn];
LL dp[maxn][2][2];
void dfs(int now){
	for (int i = 0; i < e[now].size(); i++)dfs(e[now][i]);
	memset(dp[now], 0, sizeof(dp[now]));
	dp[now][0][0] = dp[now][1][1] = 1;
	for (int pos = 0; pos < 2; pos++){
		LL sum[2]; sum[0] = sum[1] = 0;sum[1-pos]++;
		for (int i = 0; i < e[now].size(); i++){
			int v = e[now][i];
			LL t1 = sum[0], t2 = sum[1];
			sum[0] = (t1*dp[v][0][0] + t2*dp[v][1][0])%mods;
			sum[1] = (t1*dp[v][0][1] + t2*dp[v][1][1]) % mods;
		}
		dp[now][pos][0] = (dp[now][pos][0] + sum[0]*2) % mods;
		dp[now][pos][1] = (dp[now][pos][1] + sum[1]*2) % mods;

		sum[0] = sum[1] = 0;sum[1 - pos]++;
		for (int i = 0; i < e[now].size(); i++){
			int v = e[now][i];
			LL t1 = sum[0], t2 = sum[1];
			sum[0] = t1*dp[v][0][0] % mods;
			sum[1] = t2*dp[v][1][1] % mods;
		}
		dp[now][pos][0] = (dp[now][pos][0] -sum[0]) % mods;
		dp[now][pos][1] = (dp[now][pos][1] -sum[1]) % mods;

		LL a[2][2]; memset(a, 0, sizeof(a));
		a[0][1-pos]++;
		for (int i = 0; i < e[now].size(); i++){
			int v = e[now][i];
			LL t00 = a[0][0], t01 = a[0][1];
			LL t10 = a[1][0], t11 = a[1][1];
			a[1][1] = (a[1][1]+t00*dp[v][0][1])% mods;
			a[0][1] = (a[0][1] + t10*dp[v][0][1]) % mods;

			a[1][0] = (a[1][0] + t01*dp[v][1][0]) % mods;
			a[0][0] = (a[0][0] + t11*dp[v][1][0]) % mods;
		}
		dp[now][pos][0] = (dp[now][pos][0] - a[1][0]) % mods;
		dp[now][pos][1] = (dp[now][pos][1] - a[1][1]) % mods;
	}
	return;
}
int main(){
	while (scanf("%d", &n) != EOF){
		for (int i = 1; i <= n; i++)e[i].clear();
		for (int i = 2; i <= n; i++){
			int tmp; scanf("%d", &tmp);
			e[tmp].push_back(i);
		}
		for (int i = 1; i <= n; i++)sort(e[i].begin(), e[i].end());
		dfs(1);
		printf("%I64d\n", (dp[1][0][0] + dp[1][0][1] - 1 + mods) % mods);
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<climits>
#include<map>
using namespace std;
#define maxn 110000
#define LL __int64
#define mods 1000000007
int n;
vector<int> e[maxn];
LL dp[maxn][2][2];
void dfs(int now){
	for (int i = 0; i < e[now].size(); i++)dfs(e[now][i]);
	memset(dp[now], 0, sizeof(dp[now]));
	dp[now][0][0] = dp[now][1][1] = 1;
	for (int pos = 0; pos < 2; pos++){
		LL sum[2]; sum[0] = sum[1] = 0;sum[1-pos]++;
		for (int i = 0; i < e[now].size(); i++){
			int v = e[now][i];
			LL t1 = sum[0], t2 = sum[1];
			sum[0] = (t1*dp[v][0][0] + t2*dp[v][1][0])%mods;
			sum[1] = (t1*dp[v][0][1] + t2*dp[v][1][1]) % mods;
		}
		dp[now][pos][0] = (dp[now][pos][0] + sum[0]*2) % mods;
		dp[now][pos][1] = (dp[now][pos][1] + sum[1]*2) % mods;

		sum[0] = sum[1] = 0;sum[1 - pos]++;
		for (int i = 0; i < e[now].size(); i++){
			int v = e[now][i];
			LL t1 = sum[0], t2 = sum[1];
			sum[0] = t1*dp[v][0][0] % mods;
			sum[1] = t2*dp[v][1][1] % mods;
		}
		dp[now][pos][0] = (dp[now][pos][0] -sum[0]+mods) % mods;
		dp[now][pos][1] = (dp[now][pos][1] -sum[1]+mods) % mods;

		LL a[2][2]; memset(a, 0, sizeof(a));
		a[0][1-pos]++;
		for (int i = 0; i < e[now].size(); i++){
			int v = e[now][i];
			LL t00 = a[0][0], t01 = a[0][1];
			LL t10 = a[1][0], t11 = a[1][1];
			a[1][1] = (a[1][1]+t00*dp[v][0][1])% mods;
			a[0][1] = (a[0][1] + t10*dp[v][0][1]) % mods;

			a[1][0] = (a[1][0] + t01*dp[v][1][0]) % mods;
			a[0][0] = (a[0][0] + t11*dp[v][1][0]) % mods;
		}
		dp[now][pos][0] = (dp[now][pos][0] - a[1][0]+mods) % mods;
		dp[now][pos][1] = (dp[now][pos][1] - a[1][1]+mods) % mods;
	}
	return;
}
int main(){
	while (scanf("%d", &n) != EOF){
		for (int i = 1; i <= n; i++)e[i].clear();
		for (int i = 2; i <= n; i++){
			int tmp; scanf("%d", &tmp);
			e[tmp].push_back(i);
		}
		for (int i = 1; i <= n; i++)sort(e[i].begin(), e[i].end());
		dfs(1);
		printf("%I64d\n", (dp[1][0][0] + dp[1][0][1] - 1 + mods) % mods);
	}
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
typedef long long Int;
const int Maxn=100010;
const int M=1000000007;
vector<int>G[Maxn];
int n;
int dp[Maxn][2];
int reod[2],reev;
int temp[2];
void up(int &x,int y)
{
   if(y<0)y+=M;
   x+=y;if(x>=M)x-=M;
}
void dfs(int u)
{
   dp[u][1]=1;
   for(int i=0;i<G[u].size();i++)dfs(G[u][i]);
   reod[0]=1;reod[1]=0;reev=1;
   for(int i=0;i<G[u].size();i++)
   {
      int v=G[u][i];

      temp[0]=temp[1]=0;
      for(int j=0;j<2;j++)
         for(int k=0;k<2;k++)
            up(temp[(j+k)&1],dp[u][j]*(Int)dp[v][k]%M);
      for(int j=0;j<2;j++)up(dp[u][j],temp[j]);

      temp[0]=temp[1]=0;
      up(temp[0],reod[1]*(Int)dp[v][1]%M);
      up(temp[1],reod[0]*(Int)dp[v][1]%M);
      up(reod[1],temp[1]);
      up(reod[0],temp[0]);
      //if(u==1&&v==4)printf("%d\n",reod[1]);
      up(reev,reev*(Int)dp[v][0]%M);
   }
   //if(u==1)
   //printf("%d\n",reod[1]);
   up(dp[u][0],dp[u][0]);
   up(dp[u][1],dp[u][1]);
   up(dp[u][0],-reod[1]);
   up(dp[u][1],-reev);
}
int main()
{
  scanf("%d",&n);
  for(int i=2;i<=n;i++)
  {
     int u;scanf("%d",&u);
     G[u].push_back(i);
  }
  dfs(1);
  printf("%d\n",(dp[1][1]+dp[1][0])%M);
}


#include <functional>
#include <algorithm>
#include <memory.h>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstdio>
#include <complex>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <set>
#include <map>
using namespace std;

const double pi = acos(-1.0);

#define int64 long long
#define mp make_pair

#ifdef _DEBUG
    const int N = 3000;
#else
    const int N = 300000;
#endif

const int MOD = 1e9+7;

int n;
int64 dp[N][3];
vector <int> g[N];

void dfs(int v)
{
    for (int i = 0; i < g[v].size(); i++)
        dfs(g[v][i]);
    if (!g[v].size())
    {
        dp[v][1] = 1;
        dp[v][0] = 0;
        return;
    }
    int64 f1[3], f2[3], f3;
    f1[0] = 1;
    f1[1] = 0;
    f2[0] = 1;
    f2[1] = 0;
    f3 = 1;
    for (int i = 0; i < g[v].size(); i++)
    {
        int64 ff1[2], ff2[2];
        for (int j = 0; j < 2; j++)
        {
            ff1[j] = (f1[j] + dp[g[v][i]][1] * f1[j ^ 1] + dp[g[v][i]][0] * f1[j]) % MOD;
            ff2[j] = (f2[j] + dp[g[v][i]][1] * f2[j ^ 1]) % MOD;
        }
        for (int j = 0; j < 2; j++)
        {
            f1[j] = ff1[j];
            f2[j] = ff2[j];
        }
        f3 = (f3 + f3 * dp[g[v][i]][0]) % MOD;
    }
    dp[v][0] = (f1[1] * 2) % MOD;
    dp[v][0] = (MOD + dp[v][0] - f2[1]) % MOD;
    dp[v][1] = (f1[0] * 2) % MOD;
    dp[v][1] = (MOD + dp[v][1] - f3) % MOD;
}

int main()
{
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    scanf("%d", &n);
    for (int i = 1; i < n; i++)
    {
        int p;
        scanf("%d", &p);
        g[p].push_back(i + 1);
    }
    dfs(1);
    int64 ans = (dp[1][0] + dp[1][1]) % MOD;
    cout << ans;
    return 0;
}


#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <deque>
#include <stack>
#include <sstream>

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <algorithm>

using namespace std;

const long long MOD = 1000000007;

int n;

vector<int> g[100007];
long long dp[100007][2];

void dfs(int v)
{
    long long count[2] = { 0 };
    long long cnt[2] = { 0 };

    dp[v][0] = 1;
    for (int i = 0; i < (int)g[v].size(); i++)
    {
        int to = g[v][i];
        dfs(to);

        long long X = dp[v][0] * dp[to][0] + dp[v][1] * dp[to][1];
        long long Y = dp[v][0] * dp[to][1] + dp[v][1] * dp[to][0];

        dp[v][0] = X % MOD;
        dp[v][1] = Y % MOD;
    }

    count[0] = 1;
    for (int i = (int)g[v].size() - 1; i >= 0; i--)
    {
        int to = g[v][i];

        long long X = count[0] * dp[to][0] + count[1] * dp[to][1];
        long long Y = count[0] * dp[to][1] + count[1] * dp[to][0];

        cnt[1] = (cnt[1] + count[1] * (dp[to][0] - 1)) % MOD;
        cnt[0] = (cnt[0] + count[1] * dp[to][1]) % MOD;

        count[0] = X % MOD;
        count[1] = Y % MOD;
    }

    dp[v][0] += 1;
    if (g[v].size() == 0)
        dp[v][0] = 1,
        dp[v][1] = 1;

    dp[v][0] = (dp[v][0] + cnt[0]) % MOD;
    dp[v][1] = (dp[v][1] + cnt[1]) % MOD;
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #else
    //freopen("in.txt", "rt", stdin);
    //freopen("out.txt", "wt", stdout);
    #endif

    ios::sync_with_stdio(false);

    cin >> n;
    for (int i = 2; i <= n; i++)
    {
        int x; cin >> x;
        g[x].push_back(i);
    }

    dfs(1);

    cout << (dp[1][0] + dp[1][1] - 1) % MOD;
    return 0;
}


#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <deque>
#include <stack>
#include <sstream>

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <algorithm>

using namespace std;

const long long MOD = 1000000007;

int n;

vector<int> g[100007];
long long dp[100007][2];

void dfs(int v)
{
    long long odd, even;
    long long even_val = 1, odd_val = 0;
    long long odd_cnt = 0, even_cnt = 1;

    for (int i = 0; i < (int)g[v].size(); i++)
        dfs(g[v][i]);

    odd = 0; even = 1;
    for (int i = 0; i < (int)g[v].size(); i++)
    {
        int to = g[v][i];

        long long X = even * dp[to][0] + odd * dp[to][1];
        long long Y = even * dp[to][1] + odd * dp[to][0];

        even_val = even_val * dp[to][0];

        long long EVEN_CNT = even_cnt;
        long long ODD_CNT = odd_cnt;

        even_cnt = (EVEN_CNT + ODD_CNT * dp[to][1]) % MOD;
        odd_cnt = (ODD_CNT + EVEN_CNT * dp[to][1]) % MOD;

        odd_val = (odd_val + EVEN_CNT * dp[to][1]) % MOD;

        even = X % MOD;
        odd = Y % MOD;
    }

    dp[v][0] = (dp[v][0] + even) % MOD;
    dp[v][1] = (dp[v][1] + odd) % MOD;

    odd = 0; even = 1;
    for (int i = (int)g[v].size() - 1; i >= 0; i--)
    {
        int to = g[v][i];

        long long X = even * dp[to][0] + odd * dp[to][1];
        long long Y = even * dp[to][1] + odd * dp[to][0];

        even = X % MOD;
        odd = Y % MOD;
    }

    dp[v][0] = (dp[v][0] + even) % MOD;
    dp[v][1] = (dp[v][1] + odd) % MOD;

    dp[v][0] = (dp[v][0] - even_val) % MOD;
    dp[v][1] = (dp[v][1] - odd_val) % MOD;

    swap(dp[v][0], dp[v][1]);

    dp[v][0] = (dp[v][0] + 1) % MOD;
    if (g[v].size() == 0)
        dp[v][0] = 1,
        dp[v][1] = 1;
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #else
    //freopen("in.txt", "rt", stdin);
    //freopen("out.txt", "wt", stdout);
    #endif

    ios::sync_with_stdio(false);

    cin >> n;
    for (int i = 2; i <= n; i++)
    {
        int x; cin >> x;
        g[x].push_back(i);
    }

    dfs(1);

    cout << (dp[1][0] + dp[1][1] - 1) % MOD;
    return 0;
}