One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of $n$ non-negative integers.

If there are exactly $K$ distinct values in the array, then we need $k = \lceil \log_{2} K \rceil$ bits to store each value. It then takes $nk$ bits to store the whole file.

To reduce the memory consumption we need to apply some compression. One common way is to reduce the number of possible intensity values. We choose two integers $l \le r$, and after that all intensity values are changed in the following way: if the intensity value is within the range $[l;r]$, we don't change it. If it is less than $l$, we change it to $l$; if it is greater than $r$, we change it to $r$. You can see that we lose some low and some high intensities.

Your task is to apply this compression in such a way that the file fits onto a disk of size $I$ bytes, and the number of changed elements in the array is minimal possible.

We remind you that $1$ byte contains $8$ bits.

$k = \lceil log_{2} K \rceil$ is the smallest integer such that $K \le 2^{k}$. In particular, if $K = 1$, then $k = 0$.


-----Input-----

The first line contains two integers $n$ and $I$ ($1 \le n \le 4 \cdot 10^{5}$, $1 \le I \le 10^{8}$) — the length of the array and the size of the disk in bytes, respectively.

The next line contains $n$ integers $a_{i}$ ($0 \le a_{i} \le 10^{9}$) — the array denoting the sound file.


-----Output-----

Print a single integer — the minimal possible number of changed elements.


-----Examples-----
Input
6 1
2 1 2 3 4 3

Output
2

Input
6 2
2 1 2 3 4 3

Output
0

Input
6 1
1 1 2 2 3 3

Output
2



-----Note-----

In the first example we can choose $l=2, r=3$. The array becomes 2 2 2 3 3 3, the number of distinct elements is $K=2$, and the sound file fits onto the disk. Only two values are changed.

In the second example the disk is larger, so the initial file fits it and no changes are required.

In the third example we have to change both 1s or both 3s.

Difficulty: competition

Starter code:

Solutions:
N, I = list(map(int, input().split()))
A = sorted([int(a) for a in input().split()])
B = []
j = 0
for i in range(N):
    if i == 0 or A[i] == A[i-1]:
        B.append(j)
    else:
        j += 1
        B.append(j)

def calc(k):
    K = 1<<k
    i = 0
    j = 0
    ma = 0
    while j < N:
        if B[j]-B[i] <= K - 1:
            ma = max(ma, j-i+1)
            j += 1
        else:
            i += 1
    return N-ma

ans = 10**100
for i in range(31):
    if i * N <= 8 * I:
        ans = min(ans, calc(i))

print(ans)




from itertools import groupby as gb

N, I = map(int,input().split())
A = list(map(int,input().split()))
A = sorted(A)
l = []
G = gb(A)
for k, v in G:
    l.append(len(list(v)))

k = 100
while True:
    if N * k > 8 * I:
        k -= 1
    else:
        break
K = 2 ** k

NN = len(l)
if NN <= K:
    print(0)
    return

sm = sum(l[:K])
mx = sm

for i in range(K, NN):
    sm += l[i] - l[i - K]
    mx = max(mx, sm)

print(sum(l) - mx)

from math import log, floor
n,I = list(map(int, input().split()))
a = [int(s) for s in input().split()]
b = []
a.sort()
b.append([-1, 0])
for i in range(0, n):
    if a[i] == b[-1][0]:
        b[-1][1] += 1
    else:
        b.append([a[i], b[-1][1]+1])
maxk = I*8//n
maxK = 1<<maxk
# print(maxk, maxK)
ans = n
# print(b)
if len(b)-1 < maxK:
    ans = 0
else:
    for i in range(len(b)-maxK):
        chg = n-(b[i+maxK][1]-b[i][1])
        if chg < ans:
            ans = chg
print(ans)


import math

import sys
input = sys.stdin.readline

n, I = list(map(int, input().split()))
A = list(map(int, input().split()))

k = math.floor((I*8)/n)
K = 2**min(k, 20)

# find distinct
s = sorted(set(A))
dis = len(s)

# count occurence
count = {}

for i in range(n):
    if A[i] not in count:
        count[A[i]] = 1
    else:
        count[A[i]] += 1

# test eliminating
diff = max(dis - K, 0)

ct = 0
for i in range(diff):
    ct += count[s[i]]
ans = ct

for i in range(diff-1, -1, -1):
    ct -= count[s[i]]
    ct += count[s[i+K]]
    ans = min(ans, ct)

print(ans)


import sys
from collections import defaultdict
input = sys.stdin.readline


def main():
    n, I = list(map(int, input().split()))
    a = list(map(int, input().split()))
    K = 2**min(20, 8*I//n)

    a.sort()
    c = []
    pos = 0
    while pos < n:
        r = pos
        while r+1 < n and a[pos] == a[r+1]:
            r += 1
        c.append(r-pos+1)
        pos = r + 1

    if K > len(c):
        print(0)
    else:
        pref = c.copy()
        suff = c.copy()
        for i in range(1, len(c)):
            pref[i] += pref[i-1]
        for i in range(len(c)-2, -1, -1):
            suff[i] += suff[i+1]

        res = sum(c)
        l = 0
        r = K-1
        while r < len(c):
            s1 = 0 if l == 0 else pref[l-1]
            s2 = 0 if r == len(c)-1 else suff[r+1]
            res = min(res, s1+s2)
            l += 1
            r += 1

        print(res)

def __starting_point():
    main()

__starting_point()

R=lambda:map(int,input().split())
n,I=R()
a=sorted(R())
b=[0]+[i+1for i in range(n-1)if a[i]<a[i+1]]
print(n-max(y-x for x,y in zip(b,b[1<<8*I//n:]+[n])))

R=lambda:map(int,input().split())
n,I=R()
a=-1,*sorted(R())
b=[i for i in range(n)if a[i]<a[i+1]]
print(n-max(y-x for x,y in zip(b,b[1<<8*I//n:]+[n])))

R=lambda:map(int,input().split())
n,I=R()
a=[-1]+sorted(R())
b=[i for i in range(n)if a[i]<a[i+1]]
print(n-max(y-x for x,y in zip(b,b[1<<8*I//n:]+[n])))

from sys import stdin
input=stdin.readline
n,I=map(int,input().split())
a=sorted(list(map(int,input().split())))
key=[]
k=min(I*8//n,20)
K=min(2**k,n)
last=-1
for i in range(n):
    if a[i]==last:
        key[-1]+=1
    else:
        key.append(1)
        last=a[i]
now=0
best=0
for i in range(len(key)):
    if i<K:
        now+=key[i]
    else:
        now+=key[i]
        now-=key[i-K]
    best=max(now,best)
print(n-best)

from sys import stdin
input=stdin.readline
n,I=map(int,input().split())
a=sorted(list(map(int,input().split())))
key=[]
k=min(I*8//n,20)
K=min(2**k,n)
last=-1
for i in range(n):
    if a[i]==last:
        key[-1]+=1
    else:
        key.append(1)
        last=a[i]
now=best=0
for i in range(len(key)):
    if i<K:
        now+=key[i]
    else:
        now+=key[i]
        now-=key[i-K]
    best=max(now,best)
print(n-best)

import math
n,I=[int(x) for x in input().split()]
lis=[int(x) for x in input().split()]



dic=dict()

for i in lis:
    if i in dic:
        dic[i]+=1
    else:
        dic[i]=1


disLis=sorted(dic)
nowK=len(disLis)

if math.log2(nowK)>(I*8)//n:

    maxK=2**((I*8)//n)
    needMin=nowK-maxK
    
    minChange=0
    
    for i in range(needMin):
        minChange+=dic[disLis[i]]
    
    befChange=minChange
    
    for i in range(1,needMin+1):
        befChange=befChange-dic[disLis[needMin-i]]+dic[disLis[-i]]
        if befChange<minChange:
            minChange=befChange

    print(minChange)
else:
    print(0)


import math

n, I = map(int, input().split())
if I >= n*round(math.log(n,2)+0.5)/8:
    print(0)
else:
    a = sorted([x for x in map(int, input().split())])
    a=[-1]+a
    b=[i for i in range(n) if a[i] < a[i+1]]
    ans = set()
    for x in zip(b, b[2**(I*8//n):]+[n]):
        ans.add(x[1]-x[0])
    print(n-max(ans))

n,i=list(map(int,input().split()))
k=2**(8*i//n) if 8*i//n < 20 else n
a=[int(x) for x in input().split()]
a.sort()
freq = [1]
for i in range(1, len(a)):
	if a[i-1] == a[i]:
		freq[-1] += 1
	else:
		freq.append(1)
window = sum(freq[:k])
ans = window
for i in range(k, len(freq)):
	window += freq[i]
	window -= freq[i-k]
	ans = max(ans, window)

print(n-ans)


n,i=list(map(int,input().split()))
k=2**(8*i//n) if 8*i//n < 20 else n
a=[int(x) for x in input().split()]
a.sort()
freq = [1]
for i in range(1, len(a)):
	if a[i-1] == a[i]:
		freq[-1] += 1
	else:
		freq.append(1)
window = sum(freq[:k])
ans = window
for i in range(k, len(freq)):
	window += freq[i]
	window -= freq[i-k]
	ans = max(ans, window)

print(n-ans)


import math

n, m = list(map(int, input().split()))
lst = list(map(int, input().split()))

lst.sort()
last_val = -1
freq_list = []

for i in range(n):
	if lst[i] != last_val:
		last_val = lst[i]
		freq_list.append(1)
	else:
		freq_list[-1] += 1

k = len(freq_list)

for i in range(k, 0, -1):
	if n * math.ceil(math.log2(i)) <= m * 8:
		k = i
		break

mx = 0
tot = sum(freq_list[:k])
mx = max(tot, mx)
for i in range(k, len(freq_list)):
	tot = tot + freq_list[i] - freq_list[i-k]
	mx = max(mx, tot)

print(n-mx)




R=lambda:map(int,input().split())
n,I=R()
a=-1,*sorted(R())
b=[i for i in range(n)if a[i]<a[i+1]]
print(n-max(y-x for x,y in zip(b,b[1<<8*I//n:]+[n])))

from itertools import groupby


def mp3(n, I, a):
    k = int((I * 8) / n)
    d = 1 << k
    c = [len(list(group)) for (key, group) in groupby(sorted(a))]
    chgs = sum(c[d:])
    ans = chgs
    for i in range(0, len(c) - d):
        chgs += c[i]
        chgs -= c[i + d]
        ans = min(ans, chgs)
    return ans


def __starting_point():
    nn, II = list(map(int, input().split()))
    aa = list(map(int, input().split()))
    print(mp3(nn, II, aa))
__starting_point()