#!/usr/bin/python

import unittest

#def find_num_pairs_with_xor_equals_x_1(n, x, arr):
#
#    num_dict = {}
#
#    # Set the count of numbers in dict
#    for num in arr:
#        count = num_dict.get(num)
#        if count:
#            num_dict[num] += 1
#        else:
#            num_dict[num] = 1
#
#    num_pairs = 0
#
#    # Iterate over the keys instead of array as array will have
#    # duplicates
#    for num in num_dict.keys():
#        # ai ^ aj = x ==> ai ^ x = aj.
#        # Thus we check if xor of x with current number matches with
#        # any other entry in the hash. Also it should not match self
#        # For example if the input has 1 1 and x = 0 then val = 1
#        # but there is no pair which xors to 1.
#        val = num^x
#        num_count = num_dict.get(val)
#        if num_count:
#            if (val != num) or (val == num and num_count > 1):
#                num_pairs += num_dict.get(val)
#
#    # Divide into half as we have to return the number of pairs
#    print num_pairs
#    return num_pairs/2

def find_num_pairs_with_xor_equals_x(n, x, arr):

    arr.sort()
    num_pairs = 0

    # Iterate over the keys instead of array as array will have
    # duplicates
    for index, num in enumerate(arr):
        val = num^x
        for ii, nn in enumerate(arr):
            # If current number is greater than val then we early out
            # there is no point iterating over remaining numbers
            if nn > val:
                break

            # if xor equals the current number then we have a pair
            # given it is not the same number
            if val == nn and index != ii:
                num_pairs += 1

    # Divide into half as we have to return the number of pairs
    #print num_pairs/2
    return num_pairs/2

class TestSamples(unittest.TestCase):

    def test_sample_1(self):
        x = 3
        arr = [1, 2]
        self.assertEquals(find_num_pairs_with_xor_equals_x(len(arr), x, arr), 1)

    def test_sample_2(self):
        x = 1
        arr = [5, 1, 2, 3, 4, 1]
        self.assertEquals(find_num_pairs_with_xor_equals_x(len(arr), x, arr), 2)

    def test_sample_3(self):
        x = 0
        arr = [1, 1]
        self.assertEquals(find_num_pairs_with_xor_equals_x(len(arr), x, arr), 1)

    def test_sample_4(self):
        x = 0
        arr = [1, 1, 1]
        self.assertEquals(find_num_pairs_with_xor_equals_x(len(arr), x, arr), 3)

if __name__ == "__main__":
    n, x = map(int, raw_input().split(' '))
    arr = map(int, raw_input().split(' '))

    print find_num_pairs_with_xor_equals_x(n, x, arr)

    #unittest.main()


#!/usr/bin/python

import os

def find_num_pairs_with_xor_equals_x(n, x, arr):

    num_dict = {}
    # Set the count of numbers in dict
    for num in arr:
        count = num_dict.get(num)
        if count:
            num_dict[num] += 1
        else:
            num_dict[num] = 1

    num_pairs = 0
    for num in arr:
        val = num^x
        if num_dict.get(val):
            num_pairs += num_dict.get(val)

    return num_pairs/2

if __name__ == "__main__":
    n, x = map(int, raw_input().split(' '))
    arr = map(int, raw_input().split(' '))

    print find_num_pairs_with_xor_equals_x(n, x, arr)


#!/usr/bin/python

import os

def find_num_pairs_with_xor_equals_x(n, x, arr):

    num_dict = {}

    # Set the count of numbers in dict
    for num in arr:
        count = num_dict.get(num)
        if count:
            num_dict[num] += 1
        else:
            num_dict[num] = 1

    num_pairs = 0

    # Iterate over the keys instead of array as array will have
    # duplicates
    for num in num_dict.keys():
        # ai ^ aj = x ==> ai ^ x = aj.
        # Thus we check if xor of x with current number matches with
        # any other entry in the hash. Also it should not match self
        # For example if the input has 1 1 and x = 0 then val = 1
        # but there is no pair which xors to 1.
        val = num^x
        if num_dict.get(val) and val != num:
            num_pairs += num_dict.get(val)

    # Divide into half as we have to return the number of pairs
    return num_pairs/2

if __name__ == "__main__":
    n, x = map(int, raw_input().split(' '))
    arr = map(int, raw_input().split(' '))

    print find_num_pairs_with_xor_equals_x(n, x, arr)


from collections import *
import math

def xor_sum(n, x, L):
	xor_set = Counter(x^a_j for a_j in L)
	num_pairs = 0

	if x == 0:
		for a in xor_set:
			k = xor_set[a]
			combos = (k * (k-1))
			num_pairs = num_pairs + combos

	else:
		num_pairs = sum(xor_set[a_i] for a_i in L)

	return num_pairs/2

n , x = map(int, raw_input().split())

L = map(int, raw_input().split())

print (xor_sum(n,x,L))


n, x = map(int, raw_input().split())
a = list(set(map(int, raw_input().split())))

count = 0
for i in range(len(a)):
    for j in range(i + 1, len(a)):
        if a[i] ^ a[j] == x:
            count += 1

print count


n, x = map(int, raw_input().split())
a = list(set(map(int, raw_input().split())))

count = 0
for i in range(len(a)):
    for j in range(i + 1, len(a)):
        print a[i], a[j], a[i] ^ a[j]
        if a[i] ^ a[j] == x:
            count += 1

print count


n, x = map(int, raw_input().split())
a = map(int, raw_input().split())

count = 0
for i in range(len(a)):
    for j in range(i + 1, len(a)):
        if a[i] ^ a[j] == x:
            count += 1

print count


r = lambda: map(int, raw_input().split())
n, x = r()
a = r()

seen = {}
count = 0
for i in a:
    t = i ^ x

    if t in seen:
        count += seen[t]

    if i not in seen:
        seen[i] = 1
    else:
        seen[i] += 1

print count


r = lambda: map(int, raw_input().split())
n, x = r()
a = r()

seen = {}
count = 0
for i in a:
    t = i ^ x

    if i not in seen:
        seen[i] = 1
    else:
        seen[i] += 1

    if t in seen:
        count += seen[t]

print count


R = lambda: map(int, raw_input().split())
n, x = R()
a = R()

from collections import Counter

c = Counter(a)
seen = set()

count = 0
for n in a:

    if n ^ x in c  and n^x and n not in seen:
        count += c[n^x]
        seen.add(n)
        seen.add(n^x)

print count


#555555

n,x=map(int,raw_input().split())
l=map(int,raw_input().split())
ans=chk=0
d={}
for i in l:
    if i in d:
        d[i]+=1
    else:
        d[i]=1
if x==0:
    for i in d:
        ans +=d[i]*(d[i]-1)/2
    print ans
else:
    for i in d:
        if i^x in d:
            ans+=d[i]*d[i^x]
    print ans/2


n,x=map(int,raw_input().split())
l=map(int,raw_input().split())
ans=chk=0
d={}
for i in l:
    if i in d:
        d[i]+=1
    else:
        d[i]=1
if x==0:
    for i in d:
        ans+=pscl(d[i])[2]
    print ans
else:
    for i in d:
        if i^x in d:
            ans+=d[i]*d[i^x]
    print ans/2


n, x = map(int, raw_input().split())
a = map(int, raw_input().split())
r = 0
for i in range(len(a)):
    for j in range(i + 1, len(a)):
        if a[i] ^ a[j] == x:
            r += 1
print r


n, x = map(int, raw_input().split())
r = 0
b = 200005 * [0]
for k in map(int, raw_input().split()):
    r += b[k ^ x]
    b[k] += 1
print r


n, x = map(int, raw_input().split())
r = 0
b = 20005 * [0]
for k in map(int, raw_input().split()):
    r += b[k ^ x]
    b[k] += 1
print r


n, s = map(int, raw_input().split())
a = [0] * 204800
r = 0
for i in map(int, raw_input().split()):
    r += a[i ^ s]
    a[i] += 1
print r


n, s = map(int, raw_input().split())
a = [0] * 102400
r = 0
for i in map(int, raw_input().split()):
    r += a[i ^ s]
    a[i] += 1
print r


n, x = map(int, raw_input().split())
a = [int(i) for i in raw_input().split()]

m = dict()
for i in a:
    if not i in m:
        m[i] = 1
    else:
        m[i] += 1

s = 0
for i in m:
    j = x ^ i
    if j in m:
        if i == j:
            s += m[i] * (m[i] - 1)
        else:
            s += m[i] * m[j]

print(s // 2)


n, x = map(int, input().split())
a = [int(i) for i in input().split()]

m = dict()
for i in a:
    if not i in m:
        m[i] = 1
    else:
        m[i] += 1

s = 0
for i in m:
    j = x ^ i
    if j in m:
        if i == j:
            s += m[i] * (m[i] - 1)
        else:
            s += m[i] * m[j]

print(s // 2)


n,k=map(int,raw_input().split())
a=map(int,raw_input().split())
f=[0]*(10**5+5)
for i in a:
    f[i]+=1
c=0
for i in a:
    c+=f[i^k]
print c//2


n,k=map(int,raw_input().split())
a=map(int,raw_input().split())
f=[0]*(10**6)
for i in a:
    f[i]+=1
c=0
for i in a:
    c+=f[i^k]
    if k==0:
        c-=1
print c//2


n,k=map(int,raw_input().split())
a=map(int,raw_input().split())
f=[0]*(10**6)
for i in a:
    f[i]+=1
c=0
for i in a:
    c+=f[i^k]
print c//2


def ii():
	return map(int,raw_input().split())

n,x = ii()
lis = ii()
di1 = {}

for ele in lis:
	if ele in di1:
		di1[ele] += 1
	else:
		di1[ele] = 1

co = 0
for ele in di1.keys():
	if ele^x in di1 and ele^x != ele:
		co += di1[ele]*di1[ele^x]
	elif ele^x == ele:
		co += 2*di1[ele]*(di1[ele]-1)

print co/2


def ii():
	return map(int,raw_input().split())

n,x = ii()
lis = ii()
di1 = {}
co = 0
for ele in lis:
	if ele^x in di1:
		co += di1[ele^x]

	if ele in di1:
		di1[ele] += 1
	else:
		di1[ele] = 1

print co


def ii():
	return map(int,raw_input().split())

n,x = ii()
lis = ii()
di1 = {}

for ele in lis:
	if ele in di1:
		di1[ele] += 1
	else:
		di1[ele] = 1

co = 0
for ele in di1.keys():
	if ele^x in di1 and ele^x != ele:
		co += di1[ele]*di1[ele^x]
	elif ele^x == ele:
		co += 2*di[ele]*(di[ele]-1)

print co/2


from collections import defaultdict

n, x = map(int, raw_input().split())
vec = map(int, raw_input().split())

am = defaultdict(int)
res = 0
for w in vec:
    res += am.get(w^x, 0)
    am[w] += 1

print res


a = raw_input().split()
n = int(a[0])
x = int(a[1])
b = [0 for i in range(1000000)]
a = [int(i) for i in raw_input().split()]
for i in range(n):
    v = a[i]
    b[v^x]+=1
count=0

if x==0:
    for i in range(n):
        if b[a[i]]>1:
            count+=b[a[i]]-1

else:
    for i in range(n):
        count+=b[a[i]]

print count/2


a = raw_input().split()
n = int(a[0])
x = int(a[1])
b = [0 for i in range(1000000)]
a = [int(i) for i in raw_input().split()]
for i in range(n):
    v = a[i]
    b[v^x]+=1
count=0

if x==0:
    for i in range(n):
        if b[a[i]]>1:
            count+=b[a[i]]
else:
    for i in range(n):
        count+=b[a[i]]
print count/2


a = raw_input().split()
n = int(a[0])
x = int(a[1])
b = [0 for i in range(1000000)]
a = [int(i) for i in raw_input().split()]
for i in range(n):
    v = a[i]
    b[v^x]+=1
count=0

if x==0:
    for i in range(n):
        if b[a[i]]>1:
            count+=b[a[i]]

else:
    for i in range(n):
        count+=b[a[i]]
    count/=2
print count


n, x = map(int, raw_input().split())
a = map(int, raw_input().split())
d = {}
for e in a:
    if e in d:
        d[e] += 1
    else:
        d[e] = 1
ans = 0
xj = ~x
for e in a:
    xi = ~(e ^ xj)
    if xi in d and xi != e:
        ans += d[xi]
    if xi in d and xi == e:
        ans += d[xi] - 1
print ans / 2


n, x = map(int, raw_input().split())
a = map(int, raw_input().split())

ans = 0
for i in range(n-1):
    for j in range(i+1, n):
        if a[i] ^ a[j] == x:
            ans += 1

print ans


n, x = map(int, raw_input().split())
a = map(int, raw_input().split())

xai = [ai ^ x for ai in a]
# print a
# print xai

s = set([xai[-1]])
ans = 0
for i in range(n-2, -1, -1):
    # print a[i], s
    if a[i] in s:
        ans += 1
    s.add(xai[i])
print ans


n, x = map(int, raw_input().split())
a = map(int, raw_input().split())

xai = [ai ^ x for ai in a]
# print a
# print xai

s = set([xai[-1]])
ans = 0
for i in range(n-2, -1, -1):
    s.add(xai[i])
    # print a[i], s
    if a[i] in s:
        ans += 1
print ans


n, x = map(int, raw_input().split())
a = map(int, raw_input().split())

xai = [ai ^ x for ai in a]
# print a
# print xai

d = {xai[-1]: 1}
ans = 0
for i in range(n-2, -1, -1):
    # print a[i], d
    if a[i] in d:
        ans += d[a[i]]
    if xai[i] not in d:
        d[xai[i]] = 1
    else:
        d[xai[i]] += 1

print ans


a = [0]*100005
n,x = map(int, raw_input().split())
r = 0
for k in map(int, raw_input().split()):
    r+=a[x ^ k]
    a[k]+=1
print(r)


a = [0]*200005
n,x = map(int, raw_input().split())
r = 0
for k in map(int, raw_input().split()):
    r+=a[x ^ k]
    a[k]+=1
print(r)


n,x=map(int,raw_input().strip().split())
arr=map(int,raw_input().strip().split())
freq = [0]*(10**5+5)
for v in arr:
	freq[v]+=1
count,temp=0,0
for v in arr:
	temp=v^x
	if x==0:
		count+=freq[v]-1;
	elif temp<=10**5:
		count+=freq[temp]
count=int(count/2)
print count


def binary_search(arr,l,r,elem):
    if l<=r:
        mid = (l+r)/2

        if arr[mid] > elem:
            return binary_search(arr,l,mid-1,elem)
        elif arr[mid] < elem:
            return binary_search(arr,mid+1,r,elem)
        else:
            return True

    return False

COUNT = 0
di = {}
n,x = map(int,raw_input().strip().split())
A = map(int,raw_input().strip().split())
for el in A:
    if el in di:
        di[el] += 1
    else:
        di[el] = 1

#print list(B)
#A.sort()
#print di
B = di.keys()
B.sort()
#print B
l = len(B)
if x ==0:
    V = di.values()

    COUNT = sum([v*(v-1)/2 for v in V])
else:
    for i in range(l):
        ele = B[i]^x
        #print B[i],x,ele
        if binary_search(B,i+1,l-1,ele):
            COUNT += di[B[i]]*di[ele]
print COUNT


def binary_search(arr,l,r,elem):
    if l<=r:
        mid = (l+r)/2

        if arr[mid] > elem:
            return binary_search(arr,l,mid-1,elem)
        elif arr[mid] < elem:
            return binary_search(arr,mid+1,r,elem)
        else:
            return True

    return False

COUNT = 0
di = {}
n,x = map(int,raw_input().strip().split())
A = map(int,raw_input().strip().split())
for el in A:
    if el in di:
        di[el] += 1
    else:
        di[el] = 1

#print list(B)
#A.sort()
#print di
B = di.keys()
B.sort()
#print B
l = len(B)

for i in range(l):
    ele = B[i]^x
    #print B[i],x,ele
    if binary_search(B,i+1,l-1,ele):
        COUNT += di[B[i]]*di[ele]
print COUNT


from sys import stdin
import math
n,x = map(int,stdin.readline().split())
a = map(int,stdin.readline().split())
di = {}
for i in a:
    di [i] = di.get(i,0) + 1
ans = 0
if x:
    for i in a:
        ans += di.get(i^x,0)
    ans/=2
else:
    for j in di:
        y= di[j]
        ans += (y*(y-1))/2
print ans


n,x = map(int,raw_input().split())
a = map(int,raw_input().split())
d = {}
for i in a:
	d[i] = d.get(i,0)+1
ans = 0
if x:
	for i in d:
		ans += d.get(i^x,0)
	ans /= 2
else:
	for j in d:
		nn = d[j]
		ans += (nn*(nn-1))/2
print ans


n,x = map(int,raw_input().split())
a = map(int,raw_input().split())
ans = 0
for i in range(n):
	for j in range(i+1,n):
		if a[i]^a[j]==x:
			ans += 1
print ans


n,x = map(int,raw_input().split())
a = map(int,raw_input().split())
d = {}
for i in a:
	d[i] = d.get(i,0)+1
ans = 0
if x:
	for i in d:
		ans += d.get(i^x,0)
	print ans/2
else:
	for j in d:
		nn = d[j]
		ans += (nn*(nn-1))/2
	print ans


if __name__ == '__main__':
  n, x = map(int, raw_input().split())
  l = map(int, raw_input().split())
  d = {}
  total = 0
  for i in l:
    if d.has_key(i): d[i] += 1
    else: d[i] = 1
  for i in l:
    if d.has_key(x^i): total += d[x^i]
  print total/2


if __name__ == '__main__':
  n, x = map(int, raw_input().split())
  l = map(int, raw_input().split())
  d = {}
  total = 0
  for i in l:
    if d.has_key(i): d[i] += 1
    else: d[i] = 1
  for i in l:
    if d.has_key(x^i): total += d[x^i]
    if x^i == i: total -= 1
  print total/2


n, x = map(int, raw_input().split())

counter = []
for i in range(100009):
	counter.append(0)
res = 0
a = map(int, raw_input().split())
for num in a:
	xora = x ^ num
	if xora <= 100000:
		res += counter[xora]
	counter[num] += 1

print(res)


n, x = map(int, raw_input().split())

counter = []
for i in range(100009):
	counter.append(0)
res = 0
a = map(int, raw_input().split())
for num in a:
	xora = x ^ num
	res += counter[xora]
	counter[num] += 1

print(res)


n,x = map(int, raw_input().split())
l = map(int, raw_input().split())

count = {}
ans = 0
for i in l:
    if x ^ i in count:
        ans += count[x^i]
    if i in count:
        count[i] += 1
    else:
        count[i] = 0
print ans


n,x = map(int, raw_input().split())
l = map(int, raw_input().split())

count = {}
ans = 0
for i in l:
    if (x ^ i) in count:
        ans += count[x^i]
    if i in count:
        count[i] += 1
    else:
        count[i] = 1
print ans


import collections
n,x = map(int,raw_input().split())
a = map(int,raw_input().split())
f = [0]*100001
a1 = {}
for i in a:
	#print i
	if f[i]==1:
		a1[i]+=1
	else:
		a1[i]=1
		f[i]=1
#print a1
a2 = sorted(a1.keys())
s = 0
#print a1
#print a2
for i in xrange(len(a2)):
	if f[a2[i]^x]==1:
		#print bin(a2[i]), bin(x), bin(a2[i] ^ x)
		if a2[i]==a2[i]^x:
			if a1[a2[i]]>=2:
				s+=a1[a2[i]]*(a1[a2[i]]-1)/2

		else:
			s+=a1[a2[i]]*a1[a2[i]^x]
print s/2


import collections
n,x = map(int,raw_input().split())
a = map(int,raw_input().split())
f = [0]*1000001
s = 0
for i in a:
	#print i,f[:10],f[i^x]
	if f[i^x]>0:
		s += f[i^x]
	f[i]+=1
print s


import collections
n,x = map(int,raw_input().split())
a = map(int,raw_input().split())
a1 = collections.Counter(a)
a2 = a1.keys()
s = 0
#print a1
#print a2
for i in a2:
	if i^x in a2:
		#print bin(i), bin(x), bin(i ^ x)
		if i==i^x:
			if a1[i]>=2:
				s+=a1[i]*(a1[i]-1)/2

		else:
			s+=a1[i]*a1[i^x]
print s/2


import collections
n,x = map(int,raw_input().split())
a = map(int,raw_input().split())
a1 = collections.Counter(a)
a2 = sorted(a1.keys())
s = 0
#print a1
#print a2
for i in xrange(len(a2)):
	if a2[i]^x in a2[i:]:
		#print bin(a2[i]), bin(x), bin(a2[i] ^ x)
		if a2[i]==a2[i]^x:
			if a1[a2[i]]>=2:
				s+=a1[a2[i]]*(a1[a2[i]]-1)/2

		else:
			s+=a1[a2[i]]*a1[a2[i]^x]
print s


n,x = map(int, raw_input().split())
a   = map(int, raw_input().split())
m = dict()
for item in a:
	if item not in m:
		m[item] = 1
	else:
		m[item] += 1
if 0 == x:
	ans = 0
	for item in m:
		ans += (m[item]*(m[item]-1)/2)
	print ans
else:
	ans = 0
	for item in m:
		tmp = item ^ x
		if tmp in m and tmp > item:
			ans += (m[tmp] * m[item])
	print ans


import sys

def solve(l, x):
    res = 0
    d = {}
    for n in l:
        res += d.get(n ^ x, 0)
        d[n] = d.get(n, 0) + 1
    return res

l = map(int, sys.stdin.read().split())
print solve(l[2:], l[1])


#!/usr/bin/python

def main():
	l1=raw_input().split(' ')
	n=int(l1[0])
	x=int(l1[1])
	a=[]
	cnt=[0]*1000005
	ans=0
	l2=raw_input().split(' ')
	for i in range(0,n):
		temp=int(l2[i])
		a.append(temp)
	for i in range(0,n) :
		temp=a[i]^x
		ans+=cnt[temp]
		cnt[a[i]]+=1
	print ans

if __name__=='__main__':
	main()


#!/usr/bin/python

def main():
	l1=raw_input().split(' ')
	n=int(l1[0])
	x=int(l1[1])
	a=[]
	cnt=[0]*100005
	ans=0
	l2=raw_input().split(' ')
	for i in range(0,n):
		temp=int(l2[i])
		a.append(temp)
	for i in range(0,n) :
		temp=a[i]^x
		ans+=cnt[temp]
		cnt[a[i]]+=1
	print ans

if __name__=='__main__':
	main()


import sys
sys.setrecursionlimit(99999999)
i = lambda: sys.stdin.readline().strip()
ii = lambda: map(int, i().split())

n, x = ii()
ll = ii()
used = [0] * 100005
acc = 0
for e in ll:
    xx = x ^ e
    acc += used[xx]
    used[e] += 1
print acc


import sys
sys.setrecursionlimit(99999999)
i = lambda: sys.stdin.readline().strip()
ii = lambda: map(int, i().split())

n, x = ii()
ll = ii()
used = [0] * 1000005
acc = 0
for e in ll:
    xx = x ^ e
    acc += used[xx]
    used[e] += 1
print acc


import sys
sys.setrecursionlimit(99999999)
i = lambda: sys.stdin.readline().strip()
ii = lambda: map(int, i().split())

n, x = ii()
ll = ii()
used = [False] * 100005
acc = 0
for e in ll:
    xx = x ^ e
    if used[xx]: acc += 1
    used[e] = True
print acc


l=lambda:map(int,raw_input().split())
n,x = l()
a=l()
d={}
for v in a:
    d[v]=d.get(v,0)+1
c=0
for v in a:
    c+=d.get(v^x,0)
print c/2


l=lambda:map(int,raw_input().split())
n,x=l()
a=l()
d={}
for v in a:
    d[v]=d.get(v,0)+1
if x==0:
    ans=0
    for v in d.itervalues():
        ans+=v*(v-1)/2
    print ans
else:
    ans=0
    for k,v in d.iteritems():
        t=k^x
        if t in d:
            ans+=d[t]*v
    print ans/2


n, x = map(int,raw_input().split())
a = list(map(int,raw_input().split()))
coun=[0 for i in range(100001)]
for i in a:
	coun[i]+=1
count = 0
if x == 0:
	for i in a:
		count+=(coun[i]-1)
else:
	for i in a:
		if i^x<100001:
			count+=coun[i^x]

print count/2


n, x = map(int,raw_input().split())
a = list(map(int,raw_input().split()))
coun=[0 for i in range(100001)]
for i in a:
	coun[i]+=1
count = 0
for i in a:
	if i^x<100001:
		count+=coun[i^x]

print count/2


n, x = map(int,raw_input().split())
a = list(map(int,raw_input().split()))
coun=[0 for i in range(100001)]
for i in a:
	coun[i]+=1
count = 0
for i in range(len(a)):
	if a[i]^x<100001:
		count+=coun[a[i]^x]

print count/2


def find(a, n):
	l = len(a)
	if(l==0):
		return False
	if(l==1):
		if(a[0]==n):
			return True
		return False
	mid = (l-1)//2
	if a[mid]==n:
		return True
	if a[mid]>n:
		return find(a[:mid], n)
	return find(a[mid+1:], n)

n, x = map(int,raw_input().split())
a = list(map(int,raw_input().split()))
a.sort()
count = 0
for i in range(len(a)):
	if(find(a[i+1:len(a)+1], a[i]^x)):
		count+=1
print count


n, x = map(int,raw_input().split())
a = list(map(int,raw_input().split()))
coun=[0 for i in range(100001)]
a.sort()
for i in a:
	coun[i]+=1
count = 0
for i in range(len(a)):
	count+=coun[a[i]^x]

print count/2


n, x = map(int, raw_input().split())
a = map(int, raw_input().split())

ans = 0
result = {}

for i in range(n):
    if a[i] in result:
        result[a[i]] = result[a[i]] + 1
    else:
        result[a[i]] = 1

for i in range(n):
    y = x ^ a[i]
    ans += result.get(y, 0)
    if x == 0 and result.get(y, 0) != 1:
        ans -= 1

print ans / 2


n, x = map(int, raw_input().split())
a = map(int, raw_input().split())

ans = 0
result = {}

for i in range(n):
    if a[i] in result:
        result[a[i]] = result[a[i]] + 1
    else:
        result[a[i]] = 1

for i in range(n):
    y = x ^ a[i]
    ans += result.get(y, 0)
    if x == 0 and result.get(y, 0) != 0:
        ans -= 1

print ans / 2


n, x = map(int, raw_input().split())
a = map(int, raw_input().split())

ans = 0
result = {}

for i in range(n):
    if a[i] in result:
        result[a[i]] = result[a[i]] + 1
    else:
        result[a[i]] = 1

for i in range(n):
    y = x ^ a[i]
    ans += result.get(y, 0)

print ans / 2


import math
import string
import itertools
from random import *

n, x = map(int,raw_input().split())
a = map(int,raw_input().split())

dic = {}
ans = 0
for i in reversed(a):
	if i in dic:
		dic[i] += 1
	else:
		dic[i] = 1
	if i^x in dic:
		ans += dic[i^x]

print ans


import math
import string
import itertools
from random import *

n, x = map(int,raw_input().split())
a = map(int,raw_input().split())

dic = {}
ans = 0
for i in reversed(a):
	if i^x in dic:
		ans += dic[i^x]
	if i in dic:
		dic[i] += 1
	else:
		dic[i] = 1

print ans


n,k = raw_input().split()

n = int(n); k = int(k)

x = raw_input().split()

x = map(int, x)

h = [0 for i in xrange(10**6)]

count = 0

for i in x:

	temp = i ^ k

	if h[temp] > 0:

		count += h[temp]

	h[i] += 1

print count


n , x = map(int,raw_input().split() )
kp = map(int,raw_input().split() )

l = [0]*1000003
res = 0;

for i in range(0,n):
  res += (l[x^kp[i] ] )
  l[kp[i] ]+=1

print res


import re
import sys
import time

N = 100001

def read(t=None):
	string = raw_input()
	return string if t is None else [t(x) for x in string.split()]

def solve():
	n, x = read(int)

	a = read(int)

	cnt = [0 for i in range(N)]

	for i in a:
		cnt[i] += 1

	#print a

	ans = 0
	for i in a:
		j = i ^ x
		if j >= N:
			continue
		if cnt[j] == 0:
			continue
		#print "%3d xor %3d = %3d"%(i, j, x)
		if i == j:
			ans += cnt[j] - 1
		else:
			ans += cnt[j]

	print ans/2

if __name__ == "__main__":
	solve()


#include <stdio.h>

using namespace std;

int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    int res=100000;
    for(int i=1; i<=m; i++){
        int x,y;
        scanf("%d%d",&x,&y);
        if(y-x+1<res)res=y-x+1;
    }
    printf("%d\n",res);
    for(int i=1; i<=n; i++)printf("%d ",i%res);
    return 0;
}


/* DHUOJ solution #344799 @ 2018-07-08 18:46:31.186 */

#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
    int n,m,l,r;
    int Min=1e9;
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++)
    {
        scanf("%d%d",&l,&r);
        int len=r-l+1;
        Min=min(Min,len);
    }
    int counter=0;
    printf("%d\n",Min);
    for(int i=0;i<n;i++)
    {
        if(i) printf(" ");
        printf("%d",counter%Min);
        counter++;
    }
    printf("\n");
    return 0;
}


#include <iostream>
using namespace std;
int n,m,i,x=1000000001;
int main()
    {
    cin>>n>>m;
    while (cin>>i>>m)
          x=min(x,m-i+1);
    cout<<x<<endl;
    for (i=0;i<n;i++)
        cout<<i%x<<" ";
    return 0;
    }


#include <iostream>
using namespace std;
int n,m,i,x=1000000001;
int main()
    {
    cin>>n>>m;
    while (cin>>i>>m)
          x=min(x,m-i+1);
    for (i=0;i<n;i++)
        cout<<i%x<<endl;
    }


#include <cstdio>
#include <algorithm>
using namespace std;

int n, m;

int main() {
	scanf("%d%d", &n, &m);
	int dmin = n + 1;
	for (int i = 1; i <= m; i++) {
		int l, r;
		scanf("%d%d", &l, &r);
		dmin = min(dmin, r - l + 1);
	}
	printf("%d\n", dmin);
	for (int i = 1; i <= n; i++) {
		printf("%d ", i % dmin);
	}
	printf("\n");
}


#include <cstdio>
#include <algorithm>
using namespace std;

int n, m;

int main() {
	scanf("%d%d", &n, &m);
	int dmin = n + 1;
	for (int i = 1; i <= m; i++) {
		int l, r;
		scanf("%d%d", &l, &r);
		dmin = min(dmin, r - l + 1);
	}
	for (int i = 1; i <= n; i++) {
		printf("%d ", i % dmin);
	}
	printf("\n");
}


#include <bits/stdc++.h>

using namespace std;
const int maxn=1e5+5;
int l[maxn],r[maxn];
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++)
        cin>>l[i]>>r[i];
    int d=INT_MAX;
    for(int i=0;i<m;i++)
        d=min(d,r[i]-l[i]+1);
    cout<<d<<endl;
    for(int i=1;i<=n;i++){
        if(i!=1)cout<<" ";
        cout<<i%d;
    }cout<<endl;
    return 0;
}


/* DHUOJ solution #344908 @ 2018-07-08 20:43:21.827 */

#include <bits/stdc++.h>
using namespace std;
int n,m,l,r,minlen;
int main(){
    while(~scanf("%d%d",&n,&m)){
        minlen=n;
        for(int i=0;i<m;i++){
            scanf("%d%d",&l,&r);
            minlen=min(minlen,r-l+1);
        }
        printf("%d\n",minlen);
        for(int i=0;i<n;i++){
            if(i)printf(" ");
            printf("%d",i%minlen);
        }cout<<endl;
    }
    return 0;
}


/* DHUOJ solution #344740 @ 2018-07-08 18:23:21.363 */

#include <bits/stdc++.h>
using namespace std;;

int n,m;
int main()
{
  cin>>n>>m;
  int len = 1e9;
  for(int i=1;i<=m;i++){
  	int l,r;cin>>l>>r;
  	len = min(r-l+1,len);
  }
  cout<<len<<endl;
  for(int i=0;i<n;i++) cout<<i%len<<" ";
  cout<<endl;
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,m,l,r,ans=1e9;
int main(){
	scanf("%d%d",&n,&m);
	while(m--){
		scanf("%d%d",&l,&r);
		ans=min(ans,r-l+1);
	}
	printf("%d\n",ans);
	for(int i=0;i<n;i++)printf("%d ",i%ans);
	return 0;
}


/*
ID: computerbox --> Huseyn Hajiyev
LANG: C++
TASK: target_mode_on
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define _CRT_SECURE_NO_WARNINGS
//#include <boost/multiprecision/cpp_int.hpp>
//using boost::multiprecision::cpp_int;
#define FAST_READ ios_base::sync_with_stdio(0);
#define in freopen("input.txt", "r", stdin);
#define out freopen("output.txt", "w", stdout);
#define ll long long
#define debt(x,y)cout<<"#x = "<<(x)<<" and "<<"#y = "<<(y)<<endl;
#define deb(x)cout<<"#x = "<<(x)<<endl;
#define COUT(n, a) cout<< fixed << setprecision(a) << n<<endl
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define arr(a,n) for(ll i=1;i<=n;i++) cout<<a[i]<<" "; cout << "\n";
#define vecc(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout << "\n";
#define CURTIME() cerr << clock() * 1.0 / CLOCKS_PER_SEC << endl
#define DTIME(ccc) __begin = clock(); ccc; cerr<<"Time of work = "<<(clock()-__begin)/CLOCKS_PER_SEC<<endl;
#define MAXN 2000
//cin.ignore (7777, '\n');

using namespace std;
using namespace __gnu_pbds;

#define debug(args...)(Debugger()) , args
class Debugger
{
  public:
  Debugger(const std::string& _separator=", ") :
  first(true),separator(_separator){}
  template<typename ObjectType>
  Debugger& operator,(const ObjectType& v)
  {
        if(!first)cerr<<separator;
        cerr<<v;
        first=false;
        return *this;
  }
  ~Debugger() {cerr<<endl;}
  private:
    bool first;
    string separator;
};

template <typename T1, typename T2>
inline ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p)
{
   return os<<"("<<p.first<<", "<<p.second<<")";
}
template<typename T>
inline ostream &operator<<(ostream & os,const vector<T>& v)
{
    bool first=true;
    os<<"[";
    for(unsigned ll i=0;i<v.size();i++)
    {
        if(!first)os<<", ";
        os<<v[i];
        first=false;
    }
        return os<<"]";
}
template<typename T>
inline ostream &operator<<(ostream & os,const set<T>&v)
{
    bool first=true;
    os<<"[";
    for(typename set<T>::const_iterator ii=v.begin();ii!=v.end();++ii)
    {
        if(!first)os<<", ";
        os<<*ii;
        first=false;
    }
    return os<<"]";
}
template<typename T1, typename T2>
inline ostream &operator<<(ostream & os,const map<T1, T2>&v)
{
        bool first=true;
        os<<"[";
        for(typename map<T1,T2>::const_iterator ii=v.begin(); ii!=v.end();++ii)
        {
            if(!first)os<<", ";
            os<<*ii;
            first=false;
        }
        return os<<"]";
}

vector<pair<ll,ll> >nuj;
ll n,m;

ll sorthus(pair<ll,ll>a,pair<ll,ll>b)
{
  if(a.second!=b.second)return a.second<b.second;
  else return a.first<b.first;
}

ll ans[100010];

int main(){
FAST_READ;
cin>>n>>m;
for(ll i=1;i<=m;i++)
{
  ll x,y;
  cin>>x>>y;
  nuj.pb(mp(x,y));
}
ll minn=LLONG_MAX;
for(ll i=0;i<m;i++)
{
  ll l=nuj[i].first;
  ll r=nuj[i].second;
  ll cnt=0;
  minn=min(minn,r-l+1);
  for(ll j=l;j<=r;j++)
  {
	ans[j]=cnt++;
  }
}

cout<<minn<<endl;
arr(ans,n);

return 0;
}


/*
ID: computerbox --> Huseyn Hajiyev
LANG: C++
TASK: target_mode_on
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define _CRT_SECURE_NO_WARNINGS
//#include <boost/multiprecision/cpp_int.hpp>
//using boost::multiprecision::cpp_int;
#define FAST_READ ios_base::sync_with_stdio(0);
#define in freopen("input.txt", "r", stdin);
#define out freopen("output.txt", "w", stdout);
#define ll long long
#define debt(x,y)cout<<"#x = "<<(x)<<" and "<<"#y = "<<(y)<<endl;
#define deb(x)cout<<"#x = "<<(x)<<endl;
#define COUT(n, a) cout<< fixed << setprecision(a) << n<<endl
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define arr(a,n) for(ll i=1;i<=n;i++) cout<<a[i]<<" "; cout << "\n";
#define vecc(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout << "\n";
#define CURTIME() cerr << clock() * 1.0 / CLOCKS_PER_SEC << endl
#define DTIME(ccc) __begin = clock(); ccc; cerr<<"Time of work = "<<(clock()-__begin)/CLOCKS_PER_SEC<<endl;
#define MAXN 2000
//cin.ignore (7777, '\n');

using namespace std;
using namespace __gnu_pbds;

#define debug(args...)(Debugger()) , args
class Debugger
{
  public:
  Debugger(const std::string& _separator=", ") :
  first(true),separator(_separator){}
  template<typename ObjectType>
  Debugger& operator,(const ObjectType& v)
  {
        if(!first)cerr<<separator;
        cerr<<v;
        first=false;
        return *this;
  }
  ~Debugger() {cerr<<endl;}
  private:
    bool first;
    string separator;
};

template <typename T1, typename T2>
inline ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p)
{
   return os<<"("<<p.first<<", "<<p.second<<")";
}
template<typename T>
inline ostream &operator<<(ostream & os,const vector<T>& v)
{
    bool first=true;
    os<<"[";
    for(unsigned ll i=0;i<v.size();i++)
    {
        if(!first)os<<", ";
        os<<v[i];
        first=false;
    }
        return os<<"]";
}
template<typename T>
inline ostream &operator<<(ostream & os,const set<T>&v)
{
    bool first=true;
    os<<"[";
    for(typename set<T>::const_iterator ii=v.begin();ii!=v.end();++ii)
    {
        if(!first)os<<", ";
        os<<*ii;
        first=false;
    }
    return os<<"]";
}
template<typename T1, typename T2>
inline ostream &operator<<(ostream & os,const map<T1, T2>&v)
{
        bool first=true;
        os<<"[";
        for(typename map<T1,T2>::const_iterator ii=v.begin(); ii!=v.end();++ii)
        {
            if(!first)os<<", ";
            os<<*ii;
            first=false;
        }
        return os<<"]";
}

vector<pair<ll,ll> >nuj;
ll n,m;

ll sorthus(pair<ll,ll>a,pair<ll,ll>b)
{
  if(a.second!=b.second)return a.second<b.second;
  else return a.first<b.first;
}

ll ans[100010];

int main(){
FAST_READ;
cin>>n>>m;
for(ll i=1;i<=m;i++)
{
  ll x,y;
  cin>>x>>y;
  nuj.pb(mp(x,y));
}
ll minn=LLONG_MAX;
for(ll i=0;i<m;i++)
{
  ll l=nuj[i].first;
  ll r=nuj[i].second;
  ll cnt=0;
  minn=min(minn,r-l+1);
}
ll cnt=0;
for(ll i=1;i<=n;i++)
{
 ans[i]=cnt;
 cnt++;
 if(cnt==minn)cnt=0;
}

cout<<minn<<endl;
arr(ans,n);

return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb(x) push_back(x)
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define flsh fflush(stdout)
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define INF 1000000000007

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

void solve()
{
    ll n,m;
    cin>>n>>m;
    ll i;
    pll p[m];
    ll l,r;
    ll mini=INF;
    for(i=0;i<m;i++)
    {
        cin>>l>>r;
        mini=min(mini,r-l);
    }

    for(i=0;i<n;i++)
    {
        cout<<(i%(mini+1))<<" ";
    }
}

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);

if (fopen("input.txt","r" ))
  {
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
  }
cout<<setprecision(20);

ll t=1;

// cin>>t;

while(t--)
{
solve();
}

return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb(x) push_back(x)
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define flsh fflush(stdout)
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define INF 1000000000007

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

void solve()
{
    ll n,m;
    cin>>n>>m;
    ll i;
    pll p[m];
    ll l,r;
    ll mini=INF;
    for(i=0;i<m;i++)
    {
        cin>>l>>r;
        mini=min(mini,r-l);
    }
    cout<<mini+1<<"\n";
    for(i=0;i<n;i++)
    {
        cout<<(i%(mini+1))<<" ";
    }
}

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);

if (fopen("input.txt","r" ))
  {
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
  }
cout<<setprecision(20);

ll t=1;

// cin>>t;

while(t--)
{
solve();
}

return 0;
}


#include <iostream>
#include <bits/stdc++.h>
// Input macros
#define s(n)                        scanf("%d",&n)
#define sc(n)                       scanf("%c",&n)
#define sl(n)                       scanf("%lld",&n)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)
// Useful constants
#define INF                         (int)1e9
#define EPS                         1e-9
// Useful hardware instructions
#define bitcount                    __builtin_popcount
#define gcd                         __gcd
// Useful container manipulation / traversal macros
#define forall(i,a,b)               for(int i=a;i<b;i++)
#define foreach(v, c)               for( typeof( (c).begin()) v = (c).begin();  v != (c).end(); ++v)
#define all(a)                      a.begin(), a.end()
#define in(a,b)                     ( (b).find(a) != (b).end())
#define pb                          push_back
#define fill(a,v)                    memset(a, v, sizeof a)
#define sz(a)                       ((int)(a.size()))
#define mp                          make_pair
// Some common useful functions
#define maX(a,b)                     ( (a) > (b) ? (a) : (b))
#define miN(a,b)                     ( (a) < (b) ? (a) : (b))
#define checkbit(n,b)                ( (n >> b) & 1)
#define DREP(a)                      sort(all(a)); a.erase(unique(all(a)),a.end())
#define INDEX(arr,ind)               (lower_bound(all(arr),ind)-arr.begin())
using namespace std;
typedef long long ll;

int main()
{
    int n, m, l, r, ans = INF, temp;
    s(n);
    s(m);
    forall(i,0,m){
        s(l);
        s(r);
        temp = r - l + 1;
        ans = miN(ans, temp);
    }
    cout<<ans<<endl;
    forall(i,0,n){
        cout<<i % ans<<" ";
    }
    return 0;

}


#include <iostream>
#include <bits/stdc++.h>
// Input macros
#define s(n)                        scanf("%d",&n)
#define sc(n)                       scanf("%c",&n)
#define sl(n)                       scanf("%lld",&n)
#define sf(n)                       scanf("%lf",&n)
#define ss(n)                       scanf("%s",n)
// Useful constants
#define INF                         (int)1e9
#define EPS                         1e-9
// Useful hardware instructions
#define bitcount                    __builtin_popcount
#define gcd                         __gcd
// Useful container manipulation / traversal macros
#define forall(i,a,b)               for(int i=a;i<b;i++)
#define foreach(v, c)               for( typeof( (c).begin()) v = (c).begin();  v != (c).end(); ++v)
#define all(a)                      a.begin(), a.end()
#define in(a,b)                     ( (b).find(a) != (b).end())
#define pb                          push_back
#define fill(a,v)                    memset(a, v, sizeof a)
#define sz(a)                       ((int)(a.size()))
#define mp                          make_pair
// Some common useful functions
#define maX(a,b)                     ( (a) > (b) ? (a) : (b))
#define miN(a,b)                     ( (a) < (b) ? (a) : (b))
#define checkbit(n,b)                ( (n >> b) & 1)
#define DREP(a)                      sort(all(a)); a.erase(unique(all(a)),a.end())
#define INDEX(arr,ind)               (lower_bound(all(arr),ind)-arr.begin())
using namespace std;
typedef long long ll;

int main()
{
    int n, m, l, r, ans = INF, temp;
    s(n);
    s(m);
    forall(i,0,m){
        s(l);
        s(r);
        temp = r - l + 1;
        ans = miN(ans, temp);
    }
    cout<<ans<<endl;
    forall(i,0,n){
        cout<<i % ans<<" ";
    }
    return 0;
}


#include <iostream>
#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
	ll n,m,len,mex = 100009;
	cin>>n>>m;
	for(int i = 1;i<=m;i++)
	{
	    ll l,r;
	    cin>>l>>r;
	    len = (r-l+1);
	    mex = min(mex,len);
	}
	int i = 0;
	int cnt = 0;
	cout<<mex<<"\n";
	while(i<n)
	{
	    cout<<i%mex<<" ";
	    i++;
	}

	return 0;
}


#include <iostream>
#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
	ll n,m,len,mex = 100009;
	cin>>n>>m;
	for(int i = 1;i<=m;i++)
	{
	    ll l,r;
	    cin>>l>>r;
	    len = (r-l+1);
	    mex = min(mex,len);
	}
	int i = 0;
	int cnt = 0;
	cout<<mex<<"\n";
	while(i<=mex)
	{
	    cout<<i<<" ";
	    i++;
	    cnt++;
	}
	--i;
	for(int j = cnt;j<n;j++)
	{
	    cout<<--i<<" ";
	}

	return 0;
}


#include <iostream>
#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
	ll n,m,len,mex = 100009;
	cin>>n>>m;
	for(int i = 1;i<=m;i++)
	{
	    ll l,r;
	    cin>>l>>r;
	    len = (r-l+1);
	    mex = min(mex,len);
	}
	int i = 0;
	int cnt = 0;
	while(i<=mex)
	{
	    cout<<i<<" ";
	    i++;
	    cnt++;
	}
	--i;
	for(int j = cnt;j<n;j++)
	{
	    cout<<--i<<" ";
	}

	return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int m,n,l,r;
    cin>>n>>m;
    int mex=200002;
    for(int i=1;i<=m;i++)
    {
        cin>>l>>r;
        mex=min(mex,r-l+1);
    }
    cout<<mex<<endl;
    for(int i=1;i<=n;i++)
    {
        cout<<i%mex<<' ';
    }
}


#include <iostream>

using namespace std;

int main()
{
    long long a,n,b,c;
    cin>>n>>a>>b>>c;
    if(n%4==0)
        cout<<0;
    else if((n+1)%4==0)
        cout<<min(a,min(c+b,3*c));
    else if((n+2)%4==0)
        cout<<min(b,min(2*a,2*c));
    else
        cout<<min(c,min(3*a,a+b));
}


#include <iostream>

using namespace std;

int main()
{
    int n,m,l,r;
    cin>>n>>m;
    int mex=200002;
    for(int i=1;i<=m;i++)
    {
        cin>>l>>r;
        mex=min(mex,r-l+1);
    }
    cout<<mex<<endl;
    for(int i=1;i<=n;i++)
    {
        cout<<i%mex<<' ';
    }
}


#include <iostream>

using namespace std;

int main()
{
    int m,n,r,l;
    cin>>n>>m;
    int mex=200002;
    for(int i=1;i<=m;i++)
    {
        cin>>l>>r;
        mex=min(mex,r-l+1);
    }
    cout<<mex<<endl;
    for(int i=1;i<=n;i++)
    {
        cout<<i%mex<<' ';
    }
}


#include <bits/stdc++.h>
using namespace std;
#define ll int

int main() {
ll n,m;
scanf("%d%d",&n,&m);
ll len=n+10;
ll l,r;
while(m--)
{
	scanf("%d%d",&l,&r);
	if(r-l+1<len)len=r-l+1;
}
ll j=0;
printf("%d\n",len);
for(int i=1;i<=n;i++)
{

if(j==len)j=0;
	printf("%d ",j);
	j++;
}
	return 0;
           }


#include <iostream>
using namespace std;
#define ll long long int
int main() {
	ll n,m;
	scanf("%lld%lld",&n,&m);
	ll a[n];
	ll min=1e10;
	for(int i=0;i<m;i++)
	{
		ll l,r;
		scanf("%lld%lld",&r,&l);
		if(l-r+1<min)min=l-r+1;
	}
	printf("%lld\n",min);
	ll j=0;
	for(int i=0;i<n;i++){
		if(j>min)j=0;
		printf("%lld ",j);
		j++;

	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int

int main() {
ll n,m;
scanf("%lld%lld",&n,&m);
ll len=n+10;
ll l,r;
while(m--)
{
	scanf("%lld%lld",&l,&r);
	if(r-l+1<len)len=r-l+1;
}
ll j=0;
for(int i=1;i<=n;i++)
{

if(j==len)j=0;
	printf("%lld ",j);
	j++;
}
	return 0;
           }


#include<bits/stdc++.h>

    using namespace std;

    int main()
    {

        long long int i,j,k;
        long long int n,m;

        cin>>n;
        long long int a[n];

        for(i=0;i<n;i++)
            cin>>a[i];

        sort(a,a+n);

        long long int x=1;
        for(i=0;i<n;i++)
        {
            if(a[i]==x)
                x++;

            else if(x<a[i])
            {
                a[i]=x;x++;
            }
        }

        cout<<x;

        return 0;
    }


#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
using namespace std;
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    int min_mex=n;
    while(m--)
    {
        int left,right;
        scanf("%d%d",&left,&right);
        min_mex=min(min_mex,right-left+1);
    }
    printf("%d\n",min_mex);
    for(int i=1;i<=n;i++)
        printf("%d ",i%min_mex);
    printf("\n");
    return 0;
}


/*input
5 3
1 3
2 5
4 5
*/

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n, m;
    scanf("%d %d", &n, &m);
    int ans;
    for(int i = 0; i<m; i++)
    {
    	int l, r;
    	scanf("%d %d", &l, &r);
    	ans = min(ans, r - l + 1);
    }
    printf("%d\n", ans);
    printf("0");
    for(int i = 1; i<n; i++)
    {
    	printf(" %d", i%ans);
    }
    printf("\n");
	return 0;
}


/*input
4 2
1 4
2 4
*/

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n, m;
    scanf("%d %d", &n, &m);
    int ans;
    for(int i = 0; i<m; i++)
    {
    	int l, r;
    	scanf("%d %d", &l, &r);
    	ans = min(ans, r - l + 1);
    }
    printf("%d\n", ans);
    for(int i = 0; i<n; i++)
    {
    	printf("%d ", i%ans);
    }
	return 0;
}


/*input
5 3
1 3
2 5
4 5
*/

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n, m;
    scanf("%d %d", &n, &m);
    int ans = n+1;
    for(int i = 0; i<m; i++)
    {
    	int l, r;
    	scanf("%d %d", &l, &r);
    	ans = min(ans, r - l + 1);
    }
    printf("%d\n", ans);
    printf("0");
    for(int i = 1; i<n; i++)
    {
    	printf(" %d", i%ans);
    }
    printf("\n");
	return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int n,m;
	scanf("%d%d", &n, &m);

	int p = INT32_MAX;
	for(int i = 0; i < m; ++i)
	{
		int a,b;
		scanf("%d%d", &a, &b);
		p = min(p, b-a);
	}

	int j = 0;
	for(int i = 0; i < n; ++i)
	{
		printf("%d ", j);
		j = (j+1)%p;
	}
	printf("\n");

	return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int n,m;
	scanf("%d%d", &n, &m);

	int p = INT32_MAX;
	for(int i = 0; i < m; ++i)
	{
		int a,b;
		scanf("%d%d", &a, &b);
		p = min(p, abs(b-a)+1);
	}

	int j = 0;
	for(int i = 0; i < n; ++i)
	{
		printf("%d ", j);
		j = (j+1)%p;
	}
	printf("\n");

	return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int n,m;
	scanf("%d%d", &n, &m);

	int p = INT32_MAX;
	for(int i = 0; i < m; ++i)
	{
		int a,b;
		scanf("%d%d", &a, &b);
		p = min(p, abs(b-a)+1);
	}

	printf("%d\n", p);
	int j = 0;
	for(int i = 0; i < n; ++i)
	{
		printf("%d ", j);
		j = (j+1)%p;
	}
	printf("\n");

	return 0;
}


#include<bits/stdc++.H>
using namespace std;
int n,m,a,b;
int main () {
	cin>>n>>m;
	int minimum=1000000000;
	for (int i=1;i<=m;i++){
		cin>>a>>b;
		minimum=min(minimum,abs(b-a+1));
	}
	cout<<minimum<<endl;
	for (int i=0;i<n;i++){
		cout<<i%(minimum+1)<<" ";
	}
	cout<<endl;
}


#include<bits/stdc++.H>
using namespace std;
int n,m,a,b;
int main () {
	cin>>n>>m;
	int minimum=1000000000;
	for (int i=1;i<=m;i++){
		cin>>a>>b;
		minimum=min(minimum,abs(b-a)+1);
	}
	cout<<minimum<<endl;
	for (int i=0;i<n;i++){
		cout<<i%(minimum+1)<<" ";
	}
	cout<<endl;
}


#include<bits/stdc++.H>
using namespace std;
int n,m,a,b;
int main () {
	cin>>n>>m;
	int minimum=1000000000;
	for (int i=1;i<=m;i++){
		cin>>a>>b;
		minimum=min(minimum,abs(b-a)+1);
	}
	cout<<minimum<<endl;
	for (int i=0;i<n;i++){
		cout<<i%(minimum)<<" ";
	}
	cout<<endl;
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using pii = pair<ll,ll>;

using Vb = vector<bool>;
using Vi = vector<int>;
using Vll = vector<ll>;

using VVb = vector<Vb>;
using VVi = vector<Vi>;
using VVll = vector<Vll>;

using VVVb = vector<VVb>;
using VVVi = vector<VVi>;
using VVVll = vector<VVll>;

#define TRACE(x...) x
#define WATCH(x) TRACE(cout << #x << " = " << x << endl;)

#define WATCHS(x) TRACE( cout << #x" = " << x << ' ';)
#define WATCHT(x) TRACE( cout << #x" = " << x << '\t';)
#define WATCHN(x) TRACE( cout << #x" = " << x << '\n';)
#define PRINT(x...) TRACE(printf(x))

#define rep(a,i,f,x) for(ll (a) = (i); (a) <= (f); (a)+=(x))
#define repR(a,i,f,x) for(ll (a) = (f); (a) >= (i); (a)-=(x))
#define mp make_pair
#define pb push_back
#define fs first
#define se second

const ll ms = 1e9+13;

int main ()
{
  ll n,t,mex=ms,a,b;
  cin >> n >> t;
  while(t--)
  {
    cin >> a >> b;
    mex = min(mex,b-a+1);
  }

  cout  << mex << endl;
  for(int i = 0; i < n;i++)
    cout << i%mex << ' ';

  cout << endl;
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using pii = pair<ll,ll>;

using Vb = vector<bool>;
using Vi = vector<int>;
using Vll = vector<ll>;

using VVb = vector<Vb>;
using VVi = vector<Vi>;
using VVll = vector<Vll>;

using VVVb = vector<VVb>;
using VVVi = vector<VVi>;
using VVVll = vector<VVll>;

#define TRACE(x...) x
#define WATCH(x) TRACE(cout << #x << " = " << x << endl;)

#define WATCHS(x) TRACE( cout << #x" = " << x << ' ';)
#define WATCHT(x) TRACE( cout << #x" = " << x << '\t';)
#define WATCHN(x) TRACE( cout << #x" = " << x << '\n';)
#define PRINT(x...) TRACE(printf(x))

#define rep(a,i,f,x) for(ll (a) = (i); (a) <= (f); (a)+=(x))
#define repR(a,i,f,x) for(ll (a) = (f); (a) >= (i); (a)-=(x))
#define mp make_pair
#define pb push_back
#define fs first
#define se second

const ll ms = 1e9+13;

int main ()
{
  ll n,t,mex=ms,a,b;
  cin >> n >> t;
  while(t--)
  {
    cin >> a >> b;
    mex = min(mex,b-a+1);
  }

  for(int i = 0; i < n;i++)
    cout << i%mex << ' ';

  cout << endl;
}


#include <queue>
#include <functional>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <assert.h>
#define REP(i,k,n) for(int i=k;i<n;i++)
#define REPP(i,k,n) for(int i=k;i<=n;i++)
#define scan(d) scanf("%d",&d)
#define scann(n,m) scanf("%d%d",&n,&m)
#define mst(a,k)  memset(a,k,sizeof(a));
#define LL long long
#define eps 1e-8
#define INF 0x3f3f3f3f
#define mod 1000000007
#define fre  freopen("input.txt","r",stdin)
#define upmo(a,b) (((a)=((a)+(b))%mo)<0?(a)+=mo:(a))
using namespace std;
#define N 100005
#define M 15
int main()
{
  int n,m;
  scann(n,m);
  int ans = INF;
  while(m--){
   int a,b;
   scann(a,b);
   ans = min(ans, b - a + 1);
  }
  cout<<ans<<endl;
  REP(i,0,n){
  cout<<i%ans<<" ";
  }
}


#include <queue>
#include <functional>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <assert.h>
#define REP(i,k,n) for(int i=k;i<n;i++)
#define REPP(i,k,n) for(int i=k;i<=n;i++)
#define scan(d) scanf("%d",&d)
#define scann(n,m) scanf("%d%d",&n,&m)
#define mst(a,k)  memset(a,k,sizeof(a));
#define LL long long
#define eps 1e-8
#define INF 0x3f3f3f3f
#define mod 1000000007
#define fre  freopen("input.txt","r",stdin)
#define upmo(a,b) (((a)=((a)+(b))%mo)<0?(a)+=mo:(a))
using namespace std;
#define N 100005
#define M 15
int num[N];
int main()
{
  int n,m;
  scann(n,m);
  int ans = INF;
  while(m--){
   int a,b;
   scann(a,b);
   ans = min(ans, b - a + 1);
  }
  cout<<ans;
  REP(i,1,n+1){
  cout<<i%ans<<" ";
  }
}


#include <queue>
#include <functional>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <assert.h>
#define REP(i,k,n) for(int i=k;i<n;i++)
#define REPP(i,k,n) for(int i=k;i<=n;i++)
#define scan(d) scanf("%d",&d)
#define scann(n,m) scanf("%d%d",&n,&m)
#define mst(a,k)  memset(a,k,sizeof(a));
#define LL long long
#define eps 1e-8
#define INF 0x3f3f3f3f
#define mod 1000000007
#define fre  freopen("input.txt","r",stdin)
#define upmo(a,b) (((a)=((a)+(b))%mo)<0?(a)+=mo:(a))
using namespace std;
#define N 100005
#define M 15
int main()
{
  int n,m;
  scann(n,m);
  int ans = INF;
  while(m--){
   int a,b;
   scann(a,b);
   ans = min(ans, b - a + 1);
  }
  cout<<ans;
  REP(i,1,n+1){
  cout<<i%ans<<" ";
  }
}


#include<bits/stdc++.h>
#define st first
#define nd second
using namespace std;

bool comparef(pair<int,int> a, pair<int,int> b){
	return((a.nd-a.st)<(b.nd-b.st));
}
int n,m;
int main(){
	scanf("%d%d",&n,&m);
	vector<long long> v1(n+1,0), v2(n+1,-1);
	vector<pair<int,int>> pares(m);
	int a,b;
	int mex=0x3f3f3f;
	for(int i=0;i<m;i++){
		scanf("%d%d",&a,&b);
		mex=min(mex,b-a+1);
		pares[i]={a,b};
	}
	sort(pares.begin(),pares.end(),comparef);

	for(int i=0;i<m;i++){
		int a=pares[i].st;
		int b=pares[i].nd;
		set<long long> s;
		for(int j=0;j<b-a+1;j++){
			s.insert(j);
		}
		for(int j=a;j<=b;j++){
			s.erase(v2[j]);
		}
		for(int j=a;j<=b;j++){
			if(v2[j]==-1){
				if(s.size()>0){
					v2[j]=*(s.begin());
					s.erase(s.begin());
				}
			}
		}
	}
	printf("%d\n",mex);
	for(int i=1;i<=n;i++){
		if(v2[i]==-1)printf("0 ");
		else printf("%lld ",v2[i]);
	}
	puts(" ");

}


#include<bits/stdc++.h>
#define st first
#define nd second
using namespace std;

bool comparef(pair<int,int> a, pair<int,int> b){
	return((a.nd-a.st)<(b.nd-b.st));
}
int n,m;
int main(){
	scanf("%d%d",&n,&m);
	vector<long long> v1(n+1,0), v2(n+1,-1);
	vector<pair<int,int>> pares(m);
	int a,b;
	int mex=0x3f3f3f;
	for(int i=0;i<m;i++){
		scanf("%d%d",&a,&b);
		mex=min(mex,b-a+1);
		pares[i]={a,b};
	}

	int j=0;
	for(int i=0;i<n;i++){
		printf("%d ",j);
		j++;
		j=j%mex;
	}

	puts(" ");

}


#include<bits/stdc++.h>
#define st first
#define nd second
using namespace std;

bool comparef(pair<int,int> a, pair<int,int> b){
	return((a.nd-a.st)<(b.nd-b.st));
}
int n,m;
int main(){
	scanf("%d%d",&n,&m);
	vector<long long> v1(n+1,0), v2(n+1,-1);
	vector<pair<int,int>> pares(m);
	int a,b;
	int mex=0x3f3f3f;
	for(int i=0;i<m;i++){
		scanf("%d%d",&a,&b);
		mex=min(mex,b-a+1);
		pares[i]={a,b};
	}

	int j=0;
	printf("%d\n",mex);
	for(int i=0;i<n;i++){
		printf("%d ",j);
		j++;
		j=j%mex;
	}

	puts(" ");

}


#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <functional>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <iostream>
#include <ctime>
#include <complex>

#define enp 	printf("**Entry Point**\n")
#define A		first
#define B		second
#define MP		make_pair

using namespace std;

typedef long long ll;

const int INF = 0x6fffffff;
const int MINF = 0x80000000;
const int mod = 1000000007;
const int cons = 1005;
const double pi = 3.141592653589793;

int tree[400001];
int mxtree[400001];
int lim;
int mxlim;

void mxupd(int pos, int vl)
{
	pos += mxlim;
	mxtree[pos] = vl;

	while (pos > 1)
	{
		pos >>= 1;
		mxtree[pos] = max(mxtree[2 * pos], mxtree[2 * pos + 1]);
	}
}

int mxquery(int L, int R)
{
	L += mxlim;
	R += mxlim;
	int ret = 0;

	while (L < R)
	{
		ret = max(ret, max(mxtree[L++], mxtree[R--]));
		L >>= 1;
		R >>= 1;
	}
	if (L == R)ret = max(ret, mxtree[L]);

	return ret;
}

void upd(int pos, int vl)
{
	pos += lim;
	tree[pos] = vl;

	while (pos > 1)
	{
		pos >>= 1;
		tree[pos] = min(tree[2 * pos], tree[2 * pos + 1]);
	}
}

int query(int L, int R)
{
	L += lim;
	R += lim;
	int ret = INF;

	while (L < R)
	{
		ret = min(ret, min(tree[L++], tree[R--]));
		L >>= 1;
		R >>= 1;
	}

	if (L == R)ret = min(ret, tree[L]);

	return ret;
}

int ans[100001];
bool chk[100001];

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

	int n, m;
	scanf("%d%d", &n, &m);

	vector < pair <int, int> > dat;
	for (int i = 0; i < m; i++)
	{
		int l, r;
		scanf("%d%d", &l, &r);
		dat.push_back(MP(l, r));
		chk[l] = true;
	}

	int cur = 0;
	int a = 1e8;
	for (int i = 1; i <= n; i++)
	{
		if (chk[i])cur = 0;
		else cur++;
		ans[i] = cur;
	}

	int mx = 0;
	for (int i = n; i >= 1; i--)
	{
		if (ans[i] == 0)
		{
			if (mx == 0)continue;
			a = min(a, mx);
			mx = 0;
			continue;
		}

		mx = max(mx, ans[i]);
	}

	printf("%d\n", a + 1);
	for (int i = 1; i <= n; i++)
	{
		printf("%d ", ans[i]);
	}

	return 0;
}


#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <functional>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <iostream>
#include <ctime>
#include <complex>

#define enp 	printf("**Entry Point**\n")
#define A		first
#define B		second
#define MP		make_pair

using namespace std;

typedef long long ll;

const int INF = 0x6fffffff;
const int MINF = 0x80000000;
const int mod = 1000000007;
const int cons = 1005;
const double pi = 3.141592653589793;

int tree[400001];
int mxtree[400001];
int lim;
int mxlim;

void mxupd(int pos, int vl)
{
	pos += mxlim;
	mxtree[pos] = vl;

	while (pos > 1)
	{
		pos >>= 1;
		mxtree[pos] = max(mxtree[2 * pos], mxtree[2 * pos + 1]);
	}
}

int mxquery(int L, int R)
{
	L += mxlim;
	R += mxlim;
	int ret = 0;

	while (L < R)
	{
		ret = max(ret, max(mxtree[L++], mxtree[R--]));
		L >>= 1;
		R >>= 1;
	}
	if (L == R)ret = max(ret, mxtree[L]);

	return ret;
}

void upd(int pos, int vl)
{
	pos += lim;
	tree[pos] = vl;

	while (pos > 1)
	{
		pos >>= 1;
		tree[pos] = min(tree[2 * pos], tree[2 * pos + 1]);
	}
}

int query(int L, int R)
{
	L += lim;
	R += lim;
	int ret = INF;

	while (L < R)
	{
		ret = min(ret, min(tree[L++], tree[R--]));
		L >>= 1;
		R >>= 1;
	}

	if (L == R)ret = min(ret, tree[L]);

	return ret;
}

int ans[100001];

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

	int n, m;
	scanf("%d%d", &n, &m);

	vector < pair <int, int> > dat;
	for (int i = 0; i < m; i++)
	{
		int l, r;
		scanf("%d%d", &l, &r);
		dat.push_back(MP(l, r));
	}

	for (lim = 1; lim < m; lim <<= 1);
	for (mxlim = 1; mxlim < n; mxlim <<= 1);
	memset(tree, 0x3f, sizeof(tree));
	sort(dat.begin(), dat.end());

	for (int i = 0; i < m; i++)
	{
		upd(i, dat[i].B);
	}

	memset(ans, 0x3f, sizeof(ans));

	int st = -1;
	int en = -1;
	int cur = 0;
	while (cur < m)
	{
		int r = query(cur, m - 1);

		ans[r] = 0;
		if (st == -1)st = r;
		en = r;
		int t = upper_bound(dat.begin(), dat.end(), MP(r, 0)) - dat.begin();
		cur = t;
	}

	for (int i = st + 1; i <= n; i++)
	{
		if (ans[i] == 0)continue;
		ans[i] = min(ans[i], ans[i - 1] + 1);
	}

	for (int i = en - 1; i >= 1; i--)
	{
		if (ans[i] == 0)continue;
		ans[i] = min(ans[i], ans[i + 1] + 1);
	}

	for (int i = 1; i <= n; i++)
	{
		mxupd(i - 1, ans[i]);
	}

	int a = INF;

	for (int i = 0; i < dat.size(); i++)
	{
		int L = dat[i].A;
		int R = dat[i].B;

		a = min(a, mxquery(L - 1, R - 1));
	}

	cout << a + 1 << endl;

	for (int i = 1; i <= n; i++)
	{
		printf("%d ", ans[i]);
	}

	return 0;
}


#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <functional>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <iostream>
#include <ctime>
#include <complex>

#define enp 	printf("**Entry Point**\n")
#define A		first
#define B		second
#define MP		make_pair

using namespace std;

typedef long long ll;

const int INF = 0x6fffffff;
const int MINF = 0x80000000;
const int mod = 1000000007;
const int cons = 1005;
const double pi = 3.141592653589793;

int tree[400001];
int mxtree[400001];
int lim;
int mxlim;

void mxupd(int pos, int vl)
{
	pos += mxlim;
	mxtree[pos] = vl;

	while (pos > 1)
	{
		pos >>= 1;
		mxtree[pos] = max(mxtree[2 * pos], mxtree[2 * pos + 1]);
	}
}

int mxquery(int L, int R)
{
	L += mxlim;
	R += mxlim;
	int ret = 0;

	while (L < R)
	{
		ret = max(ret, max(mxtree[L++], mxtree[R--]));
		L >>= 1;
		R >>= 1;
	}
	if (L == R)ret = max(ret, mxtree[L]);

	return ret;
}

void upd(int pos, int vl)
{
	pos += lim;
	tree[pos] = vl;

	while (pos > 1)
	{
		pos >>= 1;
		tree[pos] = min(tree[2 * pos], tree[2 * pos + 1]);
	}
}

int query(int L, int R)
{
	L += lim;
	R += lim;
	int ret = INF;

	while (L < R)
	{
		ret = min(ret, min(tree[L++], tree[R--]));
		L >>= 1;
		R >>= 1;
	}

	if (L == R)ret = min(ret, tree[L]);

	return ret;
}

int ans[100001];

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

	int n, m;
	scanf("%d%d", &n, &m);

	vector < pair <int, int> > dat;
	for (int i = 0; i < m; i++)
	{
		int l, r;
		scanf("%d%d", &l, &r);
		dat.push_back(MP(l, r));
	}

	for (lim = 1; lim < m; lim <<= 1);
	for (mxlim = 1; mxlim < n; mxlim <<= 1);
	memset(tree, 0x3f, sizeof(tree));
	sort(dat.begin(), dat.end());

	for (int i = 0; i < m; i++)
	{
		upd(i, dat[i].B);
	}

	memset(ans, 0x3f, sizeof(ans));

	int st = -1;
	int en = -1;
	int cur = 0;
	while (cur < m)
	{
		int r = query(cur, m - 1);

		ans[r] = 0;
		if (st == -1)st = r;
		en = r;
		cur = upper_bound(dat.begin(), dat.end(), MP(r, INF)) - dat.begin();
	}

	for (int i = st + 1; i <= n; i++)
	{
		if (ans[i] == 0)continue;
		ans[i] = min(ans[i], ans[i - 1] + 1);
	}

	for (int i = en - 1; i >= 1; i--)
	{
		if (ans[i] == 0)continue;
		ans[i] = min(ans[i], ans[i + 1] + 1);
	}

	for (int i = 1; i <= n; i++)
	{
		mxupd(i - 1, ans[i]);
	}

	int a = INF;

	for (int i = 0; i < dat.size(); i++)
	{
		int L = dat[i].A;
		int R = dat[i].B;

		a = min(a, mxquery(L - 1, R - 1));
	}

	cout << a + 1 << endl;

	for (int i = 1; i <= n; i++)
	{
		printf("%d ", ans[i]);
	}

	return 0;
}


#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <functional>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <iostream>
#include <ctime>
#include <complex>

#define enp 	printf("**Entry Point**\n")
#define A		first
#define B		second
#define MP		make_pair

using namespace std;

typedef long long ll;

const int INF = 0x6fffffff;
const int MINF = 0x80000000;
const int mod = 1000000007;
const int cons = 1005;
const double pi = 3.141592653589793;

int tree[400001];
int mxtree[400001];
int lim;
int mxlim;

void mxupd(int pos, int vl)
{
	pos += mxlim;
	mxtree[pos] = vl;

	while (pos > 1)
	{
		pos >>= 1;
		mxtree[pos] = max(mxtree[2 * pos], mxtree[2 * pos + 1]);
	}
}

int mxquery(int L, int R)
{
	L += mxlim;
	R += mxlim;
	int ret = 0;

	while (L <= R)
	{
		ret = max(ret, max(mxtree[L++], mxtree[R--]));
		L >>= 1;
		R >>= 1;
	}

	return ret;
}

void upd(int pos, int vl)
{
	pos += lim;
	tree[pos] = vl;

	while (pos > 1)
	{
		pos >>= 1;
		tree[pos] = min(tree[2 * pos], tree[2 * pos + 1]);
	}
}

int query(int L, int R)
{
	L += lim;
	R += lim;
	int ret = INF;

	while (L <= R)
	{
		ret = min(ret, min(tree[L++], tree[R--]));
		L >>= 1;
		R >>= 1;
	}

	return ret;
}

int ans[100001];

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

	int n, m;
	scanf("%d%d", &n, &m);

	vector < pair <int, int> > dat;
	for (int i = 0; i < m; i++)
	{
		int l, r;
		scanf("%d%d", &l, &r);
		dat.push_back(MP(l, r));
	}

	for (lim = 1; lim < m; lim <<= 1);
	for (mxlim = 1; mxlim < n; mxlim <<= 1);
	memset(tree, 0x3f, sizeof(tree));
	sort(dat.begin(), dat.end());

	for (int i = 0; i < m; i++)
	{
		upd(i, dat[i].B);
	}

	memset(ans, 0x3f, sizeof(ans));

	int st = -1;
	int en = -1;
	int cur = 0;
	while (cur < m)
	{
		int r = query(cur, m - 1);

		ans[r] = 0;
		if (st == -1)st = r;
		en = r;
		int t = upper_bound(dat.begin(), dat.end(), MP(r, 0)) - dat.begin();
		cur = t;
	}

	for (int i = st + 1; i <= n; i++)
	{
		if (ans[i] == 0)continue;
		ans[i] = min(ans[i], ans[i - 1] + 1);
	}

	for (int i = en - 1; i >= 1; i--)
	{
		if (ans[i] == 0)continue;
		ans[i] = min(ans[i], ans[i + 1] + 1);
	}

	for (int i = 1; i <= n; i++)
	{
		mxupd(i - 1, ans[i]);
	}

	int a = INF;

	for (int i = 0; i < dat.size(); i++)
	{
		int L = dat[i].A;
		int R = dat[i].B;

		a = min(a, mxquery(L - 1, R - 1));
	}

	cout << a + 1 << endl;

	for (int i = 1; i <= n; i++)
	{
		printf("%d ", ans[i]);
	}

	return 0;
}


#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <functional>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <iostream>
#include <ctime>
#include <complex>

#define enp 	printf("**Entry Point**\n")
#define A		first
#define B		second
#define MP		make_pair

using namespace std;

typedef long long ll;

const int INF = 0x6fffffff;
const int MINF = 0x80000000;
const int mod = 1000000007;
const int cons = 1005;
const double pi = 3.141592653589793;

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

	int n, m;
	scanf("%d%d", &n, &m);

	int ans = INF;
	for (int i = 0; i < m; i++)
	{
		int l, r;
		scanf("%d%d", &l, &r);
		ans = min(ans, r - l + 1);
	}

	printf("%d\n", ans);
	for (int i = 1; i <= n; i++)
	{
		printf("%d ", i%ans);
	}

	return 0;
}


using namespace std;

#include<iostream>

int main(void)
{
    ios::sync_with_stdio(false);
    long n, m, l, r, range, i, j, cur, ans = 999999999;

    cin>>n>>m;
    long aray[n+1];

    for(i=1; i<=m; i++){
        cin>>l>>r;
        range = r - l + 1;
        ans = min(ans, range);
    }
    cur = 0;
    for(i=1; i<=n; i++){
        if(cur==ans) cur = 0;
        aray[i] = cur;
        cur++;
    }

    cout<<ans<<endl;
    for(i=1; i<=n; i++) cout<<aray[i]<<" ";

return 0;
}


using namespace std;

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

struct data{
    long l, r, range;

    bool operator < (const data &b) const{
        if(b.range==range) return b.l>l;
        else return b.range>range;
    }
} temp;
int main(void)
{
    ios::sync_with_stdio(false);
    long n, m, l, r, range, i, j, k, iter, ans = 999999999;

    cin>>n>>m;
    long aray[n+1];
    memset(aray, -1, sizeof(aray));
    vector<data> sub;

    for(i=1; i<=m; i++){
        cin>>l>>r;
        range = r - l + 1;
        ans = min(ans, range);
        temp.l = l; temp.r = r; temp.range = range;
        sub.push_back(temp);
    }

    sort(sub.begin(), sub.end());

    /*for(i=0; i<m; i++){
        temp = sub[i];
        cout<<temp.l<<" "<<temp.r<<endl;
    }*/

    for(iter=0; iter<sub.size(); iter++){
        temp = sub[iter];
        l = temp.l;
        r = temp.r;

        map<long, short> cmap;

        for(i=l; i<=r; i++) cmap[aray[i]] = 1;
        j = 0;
        for(i=l; i<=r; i++){
            if(aray[i]==-1){
                while(cmap[j]==1) j++;
                cmap[j] = 1;
                aray[i] = j;
            }
        }
    }
    for(i=1; i<=n; i++) if(aray[i]==-1) aray[i] = 0;
    cout<<ans<<endl;
    for(i=1; i<=n; i++) cout<<aray[i]<<" ";

return 0;
}


using namespace std;

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

struct data{
    long l, r, range;

    bool operator < (const data &b) const{
        if(b.range==range) return b.l>l;
        else return b.range>range;
    }
} temp;
int main(void)
{
    ios::sync_with_stdio(false);
    long n, m, l, r, range, i, j, counter = 0, iter, ans = 999999999;

    cin>>n>>m;
    long aray[n+1];
    memset(aray, -1, sizeof(aray));
    vector<data> sub;

    for(i=1; i<=m; i++){
        cin>>l>>r;
        range = r - l + 1;
        ans = min(ans, range);
        temp.l = l; temp.r = r; temp.range = range;
        sub.push_back(temp);
    }

    sort(sub.begin(), sub.end());

    /*for(i=0; i<m; i++){
        temp = sub[i];
        cout<<temp.l<<" "<<temp.r<<endl;
    }*/

    for(iter=0; iter<sub.size(); iter++){
        temp = sub[iter];
        l = temp.l;
        r = temp.r;

        map<long, short> cmap;

        for(i=l; i<=r; i++) cmap[aray[i]] = 1;
        j = 0;
        for(i=l; i<=r; i++){
            if(aray[i]==-1){
                while(cmap[j]==1) j++;
                cmap[j] = 1;
                aray[i] = j;
                counter++;
            }
        }
        if(counter==n) break;
    }
    for(i=1; i<=n; i++) if(aray[i]==-1) aray[i] = 0;
    cout<<ans<<endl;
    for(i=1; i<=n; i++) cout<<aray[i]<<" ";

return 0;
}


#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M 1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 10000000000000000
#define N 200005
#define vi vector<int>
#define all(v) v.begin(),v.end()
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int solve()
{
   int n,m;
   cin>>n>>m;
   vector<pii>v;
   int mn=1e9;
   rep(i,0,m)
   {
       int x,y;
       cin>>x>>y;
       v.pb({x,y});
       mn=min(mn,(y-x+1));
   }
   cout<<mn<<endl;
   for(int i=0;i<n;i++)
    cout<<(i)%mn<<" ";
   cout<<endl;

}
signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int t;
   //cin>>t;
   t=1;
   while(t--)
   {
       solve();
   }

}


#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M 1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 10000000000000000
#define N 200005
#define vi vector<int>
#define all(v) v.begin(),v.end()
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int solve()
{
   int n,m;
   cin>>n>>m;
   vector<pii>v;
   int mn=1e9;
   rep(i,0,m)
   {
       int x,y;
       cin>>x>>y;
       v.pb({x,y});
       mn=min(mn,(y-x+1));
   }
   cout<<mn+1<<endl;
   for(int i=0;i<n;i++)
    cout<<(i)%mn<<" ";
   cout<<endl;

}
signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int t;
   //cin>>t;
   t=1;
   while(t--)
   {
       solve();
   }

}


#include <bits/stdc++.h>

using namespace std;

const int N = 1e5;

int l[N], r[N];

int main() {
	int n, m;
	scanf("%d %d", &n, &m);

	for (int i = 0; i < m; ++i) {
		scanf("%d %d", &l[i], &r[i]);
	}

	for (int i = 0; i < n; ++i) {
		printf("%d ",i);
	}
	puts("");
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1e5;

int l[N], r[N];

int main() {
	int n, m;
	scanf("%d %d", &n, &m);

	for (int i = 0; i < m; ++i) {
		scanf("%d %d", &l[i], &r[i]);
	}

	for (int i = 0; i < n; ++i) {
		printf("%d ",i);
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	int n, m, mini = 2e9;
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; ++i) {
		int x, y;
		scanf("%d %d", &x, &y);
		mini = min(mini, y - x + 1);
	}
	for (int i = 0; i < n; ++i) {
		printf("%d ", i % mini);
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1e5;

int l[N], r[N];

int main() {
	int n, m;
	scanf("%d %d", &n, &m);

	for (int i = 0; i < m; ++i) {
		scanf("%d %d", &l[i], &r[i]);
	}

	for (int i = 0; i < n; ++i) {
		printf("%d ",i);
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
	int n, m, mini = 2e9;
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; ++i) {
		int x, y;
		scanf("%d %d", &x, &y);
		mini = min(mini, y - x + 1);
	}
	printf("%d\n", mini);
	for (int i = 0; i < n; ++i) {
		printf("%d ", i % mini);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define Max(a,b,c) max(a,max(b,c))
#define Min(a,b,c) min(a,min(b,c))
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define pc(x)  __builtin_popcount (x)
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define ld long double
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod 1000000007
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define flush fflush(stdout)
#define gcd __gcd
#define primeDEN 727999983
#define nx_pe next_permutation(s.begin(),s.end())
#define cl cout<<"\n"
#define sp(x) setprecision(x)
const ll N=1e5+5;
ll a[N],p[N];
vector<ll>s[N],e[N];
bool st[N],en[N];

void solve()
{
    ll n,m;
    cin>>n>>m;
    ll ans=1e9;
    vector<pll>v;
    rep(i,n)a[i]=1e9;
    rep(i,m){
        ll x,y;
        cin>>x>>y;
        ans=min(ans,y-x+1);
    }
    cout<<ans<<"\n";

    rep(i,n){
        a[i]=i%ans;
        cout<<a[i]<<" ";
    }
    cl;

}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin) ;
    freopen("ouput.txt", "w", stdout) ;
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL) ; cout.tie(NULL) ;
    std::ios::sync_with_stdio(false);
    ll te=1;
    // cin>>te;
    while(te--){
        solve();
    }

}


#include <bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define Max(a,b,c) max(a,max(b,c))
#define Min(a,b,c) min(a,min(b,c))
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define pc(x)  __builtin_popcount (x)
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define ld long double
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod 1000000007
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define flush fflush(stdout)
#define gcd __gcd
#define primeDEN 727999983
#define nx_pe next_permutation(s.begin(),s.end())
#define cl cout<<"\n"
#define sp(x) setprecision(x)
const ll N=1e5+5;
ll a[N],p[N];
vector<ll>s[N],e[N];
bool st[N],en[N];

void solve()
{
    ll n,m;
    cin>>n>>m;
    ll ans=1e9;
    vector<pll>v;
    rep(i,n)a[i]=1e9;
    rep(i,m){
        ll x,y;
        cin>>x>>y;
        ans=min(ans,y-x+1);
    }

    rep(i,n){
        a[i]=i%ans;
        cout<<a[i]<<" ";
    }
    cl;

}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin) ;
    freopen("ouput.txt", "w", stdout) ;
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL) ; cout.tie(NULL) ;
    std::ios::sync_with_stdio(false);
    ll te=1;
    // cin>>te;
    while(te--){
        solve();
    }

}


/*input
4 2
1 4
2 4

5 3
1 3
2 5
4 5

4 2
1 4
2 4

4 2
1 4
2 4

4 2
1 4
2 4

*/

/*
When you walk through a storm
Hold your head up high
And don't be afraid of the dark
At the end of the storm
There's a golden sky
And the sweet silver song
of the lark
Walk on, through the wind
Walk on, through the rain
Though your dreams be tossed
and blown
Walk on, walk on
With hope in your heart
And you'll never walk alone
YNWA
*/

//hell_hacker
//IT TAKES EVERYTHING and IT IS NOT LUCK
//PICK ME LAST -- COME OUT OF N^WHERE

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define fo(i,n) for(i=0;i<n;++i)
#define forr(i,n) for(i=n-1;i>=0;--i)

#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define yolo "debug_statement"

typedef long long int ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

const ll inf = 1e9;
const ld eps = 1e-9;
const ld pi=acos(-1);
const ll mod=1000000007;

ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

#if DEBUG && !ONLINE_JUDGE

    #define debug(args...)     (Debugger()) , args

    class Debugger
    {
        public:
        Debugger(const std::string& _separator = ", ") :
        first(true), separator(_separator){}

        template<typename ObjectType>
        Debugger& operator , (const ObjectType& v)
        {
            if(!first)
                std::cerr << separator;
            std::cerr << v;
            first = false;
            return *this;
        }
        ~Debugger() {  std::cerr << endl;}

        private:
        bool first;
        std::string separator;
    };

    template <typename T1, typename T2>
    inline std::ostream& operator << (std::ostream& os, const std::pair<T1, T2>& p)
    {
        return os << "(" << p.first << ", " << p.second << ")";
    }

    template <typename T1, unsigned long int N>
    inline std::ostream& operator << (std::ostream& os, const std::array<T1, N>& a){
        bool first = true;
        os << "[";
        for(unsigned int i = 0; i < N; i++)
        {
            if(!first)
                os << ", ";
            os << a[i];
            first = false;
        }
        return os << "]";
    }

    template<typename T>
    inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v)
    {
        bool first = true;
        os << "[";
        for(unsigned int i = 0; i < v.size(); i++)
        {
            if(!first)
                os << ", ";
            os << v[i];
            first = false;
        }
        return os << "]";
    }

    template<typename T>
    inline std::ostream &operator << (std::ostream & os,const std::set<T>& v)
    {
        bool first = true;
        os << "[";
        for (typename std::set<T>::const_iterator iii = v.begin(); iii != v.end(); ++iii)
        {
            if(!first)
                os << ", ";
            os << *iii;
            first = false;
        }
        return os << "]";
    }

    template<typename T1, typename T2>
    inline std::ostream &operator << (std::ostream & os,const std::map<T1, T2>& v)
    {
        bool first = true;
        os << "[";
        for (typename std::map<T1, T2>::const_iterator iii = v.begin(); iii != v.end(); ++iii)
        {
            if(!first)
                os << ", ";
            os << *iii ;
            first = false;
        }
        return os << "]";
    }

#else
    #define debug(args...)                  // Just strip off all debug tokens
#endif

// typedef struct{
// 	ll b, e;
// }helik;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	int i, j, n, m;
	ll x, y;
	cin >> n >> m;
	int arr[n] = {0};

	memset(arr,-1,sizeof(arr));

	vector<pair<ll,ll>>op;

	ll mx = 123123123123;

	fo(i,m){
		cin >> x >> y;
		x--;y--;
		mx = min(mx,y-x+1);
		op.pb({y-x+1,x});
	}

	cout << mx << endl;

	sort(all(op));

	// for(auto it: op)cout << it << endl;

	for(i=0;i<n;++i)
		arr[i] = 100000000;

    for(auto it: op){
        ll ct = 0;
        ll kitne = it.fi;
        ll pos = it.se;
        while(kitne > 0 && pos < n){
            if(arr[pos] == 100000000){
                arr[pos++] = ct++;
                kitne--;
            }
            else{
                pos = pos + mx - arr[pos] + 1;
                if(pos >= n)break;
                kitne = kitne - (mx - arr[pos]);
                if(mx == arr[pos]){
                    pos++;
                    kitne--;
                }
            }
        }
    }

	for(i=0;i<n;++i)cout << arr[i] << " ";
	cout << endl;

    return 0;
}


/*input
5 3
1 3
2 5
4 5

4 2
1 4
2 4

4 2
1 4
2 4

*/

/*
When you walk through a storm
Hold your head up high
And don't be afraid of the dark
At the end of the storm
There's a golden sky
And the sweet silver song
of the lark
Walk on, through the wind
Walk on, through the rain
Though your dreams be tossed
and blown
Walk on, walk on
With hope in your heart
And you'll never walk alone
YNWA
*/

//hell_hacker
//IT TAKES EVERYTHING and IT IS NOT LUCK
//PICK ME LAST -- COME OUT OF N^WHERE

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define fo(i,n) for(i=0;i<n;++i)
#define forr(i,n) for(i=n-1;i>=0;--i)

#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define yolo "debug_statement"

typedef long long int ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

const ll inf = 1e9;
const ld eps = 1e-9;
const ld pi=acos(-1);
const ll mod=1000000007;

ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

#if DEBUG && !ONLINE_JUDGE

    #define debug(args...)     (Debugger()) , args

    class Debugger
    {
        public:
        Debugger(const std::string& _separator = ", ") :
        first(true), separator(_separator){}

        template<typename ObjectType>
        Debugger& operator , (const ObjectType& v)
        {
            if(!first)
                std::cerr << separator;
            std::cerr << v;
            first = false;
            return *this;
        }
        ~Debugger() {  std::cerr << endl;}

        private:
        bool first;
        std::string separator;
    };

    template <typename T1, typename T2>
    inline std::ostream& operator << (std::ostream& os, const std::pair<T1, T2>& p)
    {
        return os << "(" << p.first << ", " << p.second << ")";
    }

    template <typename T1, unsigned long int N>
    inline std::ostream& operator << (std::ostream& os, const std::array<T1, N>& a){
        bool first = true;
        os << "[";
        for(unsigned int i = 0; i < N; i++)
        {
            if(!first)
                os << ", ";
            os << a[i];
            first = false;
        }
        return os << "]";
    }

    template<typename T>
    inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v)
    {
        bool first = true;
        os << "[";
        for(unsigned int i = 0; i < v.size(); i++)
        {
            if(!first)
                os << ", ";
            os << v[i];
            first = false;
        }
        return os << "]";
    }

    template<typename T>
    inline std::ostream &operator << (std::ostream & os,const std::set<T>& v)
    {
        bool first = true;
        os << "[";
        for (typename std::set<T>::const_iterator iii = v.begin(); iii != v.end(); ++iii)
        {
            if(!first)
                os << ", ";
            os << *iii;
            first = false;
        }
        return os << "]";
    }

    template<typename T1, typename T2>
    inline std::ostream &operator << (std::ostream & os,const std::map<T1, T2>& v)
    {
        bool first = true;
        os << "[";
        for (typename std::map<T1, T2>::const_iterator iii = v.begin(); iii != v.end(); ++iii)
        {
            if(!first)
                os << ", ";
            os << *iii ;
            first = false;
        }
        return os << "]";
    }

#else
    #define debug(args...)                  // Just strip off all debug tokens
#endif

// typedef struct{
// 	ll b, e;
// }helik;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	int i, j, n, m;
	ll x, y;
	cin >> n >> m;
	int arr[n] = {0};

	memset(arr,-1,sizeof(arr));

	vector<pair<ll,ll>>op;

	ll mn = 123123123123;

	fo(i,m){
		cin >> x >> y;
		x--;y--;
		mn = min(mn,y-x+1);
		op.pb({y-x+1,x});
	}

	cout << mn << endl;

	sort(all(op));

	// for(auto it: op)cout << it << endl;

	for(i=0;i<n;++i)
		arr[i] = 100000000;

	for(auto it: op){

		j = it.se;

		while(arr[j++]<100000000)continue;

		ll ct = 0;
		for(i=0;i<mn && j<n;++i){
			arr[j++] = ct++;
		}

		// ll ct = 0;
		// for(j=0;j<it.fi;++j){
		// 	if(arr[it.se+j]>=0){
		// 		ct++;continue;
		// 	}
		// 	arr[it.se+j] = ct;
		// 	// cout << it.se << " " << j << " " << ct << endl;return 0;
		// 	ct++;
		// }
	}

	for(i=0;i<n;++i)cout << arr[i] << " ";
	cout << endl;

    return 0;
}


/*input

5 3
1 3
2 5
4 5

10 3
4 10
2 8
3 9

*/

/*
When you walk through a storm
Hold your head up high
And don't be afraid of the dark
At the end of the storm
There's a golden sky
And the sweet silver song
of the lark
Walk on, through the wind
Walk on, through the rain
Though your dreams be tossed
and blown
Walk on, walk on
With hope in your heart
And you'll never walk alone
YNWA
*/

//hell_hacker
//IT TAKES EVERYTHING and IT IS NOT LUCK
//PICK ME LAST -- COME OUT OF N^WHERE

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define fo(i,n) for(i=0;i<n;++i)
#define forr(i,n) for(i=n-1;i>=0;--i)

#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define yolo "debug_statement"

typedef long long int ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

const ll inf = 1e9;
const ld eps = 1e-9;
const ld pi=acos(-1);
const ll mod=1000000007;

ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

#if DEBUG && !ONLINE_JUDGE

    #define debug(args...)     (Debugger()) , args

    class Debugger
    {
        public:
        Debugger(const std::string& _separator = ", ") :
        first(true), separator(_separator){}

        template<typename ObjectType>
        Debugger& operator , (const ObjectType& v)
        {
            if(!first)
                std::cerr << separator;
            std::cerr << v;
            first = false;
            return *this;
        }
        ~Debugger() {  std::cerr << endl;}

        private:
        bool first;
        std::string separator;
    };

    template <typename T1, typename T2>
    inline std::ostream& operator << (std::ostream& os, const std::pair<T1, T2>& p)
    {
        return os << "(" << p.first << ", " << p.second << ")";
    }

    template <typename T1, unsigned long int N>
    inline std::ostream& operator << (std::ostream& os, const std::array<T1, N>& a){
        bool first = true;
        os << "[";
        for(unsigned int i = 0; i < N; i++)
        {
            if(!first)
                os << ", ";
            os << a[i];
            first = false;
        }
        return os << "]";
    }

    template<typename T>
    inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v)
    {
        bool first = true;
        os << "[";
        for(unsigned int i = 0; i < v.size(); i++)
        {
            if(!first)
                os << ", ";
            os << v[i];
            first = false;
        }
        return os << "]";
    }

    template<typename T>
    inline std::ostream &operator << (std::ostream & os,const std::set<T>& v)
    {
        bool first = true;
        os << "[";
        for (typename std::set<T>::const_iterator iii = v.begin(); iii != v.end(); ++iii)
        {
            if(!first)
                os << ", ";
            os << *iii;
            first = false;
        }
        return os << "]";
    }

    template<typename T1, typename T2>
    inline std::ostream &operator << (std::ostream & os,const std::map<T1, T2>& v)
    {
        bool first = true;
        os << "[";
        for (typename std::map<T1, T2>::const_iterator iii = v.begin(); iii != v.end(); ++iii)
        {
            if(!first)
                os << ", ";
            os << *iii ;
            first = false;
        }
        return os << "]";
    }

#else
    #define debug(args...)                  // Just strip off all debug tokens
#endif

// typedef struct{
// 	ll b, e;
// }helik;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	int i, j, n, m;
	ll x, y;
	cin >> n >> m;
	int arr[n] = {0};

	memset(arr,-1,sizeof(arr));

	vector<pair<ll,ll>>op;

	ll mx = 123123123123;

	fo(i,m){
		cin >> x >> y;
		x--;y--;
		mx = min(mx,y-x+1);
		op.pb({y-x+1,x});
	}

	cout << mx << endl;

    // mx--;

	sort(all(op));

	// for(auto it: op)cout << it << endl;

	for(i=0;i<n;++i)
		arr[i] = 100000000;

    ll mini;
    ll maxi;

    // map<int,int>m;
    // map<int,int>::iterator mit;

    // for(auto it: op){
    //     ll ct = 0;
    //     ll kitne = it.fi;
    //     ll pos = it.se;

    //     for(i=0)

    // }

    for(auto it: op){
        ll ct = 0;
        ll kitne = it.fi;
        ll pos = it.se;
        while(kitne > 0){
            if(arr[pos] >= 100000000){
                arr[pos++] = ct;
                ct++;
                ct = min(mx-1,ct);
                kitne--;
            }
            else{
                kitne = kitne - (mx - arr[pos]);
                pos = pos + mx - arr[pos];
                if(arr[pos] >= 100000000)continue;
                while(kitne--){
                    if(arr[pos] < 100000000){
                        pos++;
                        ct++;
                        ct = min(mx-1,ct);
                        continue;
                    }
                    arr[pos++] = ct;
                    ct++;
                    ct = min(mx-1,ct);
                }
            }
        }
    }

	for(i=0;i<n;++i)cout << arr[i] << " ";
	cout << endl;

    return 0;
}


/*input
6 2
1 3
3 5

6 5
1 1
3 3
4 4
5 5
3 5

5 3
1 3
2 5
4 5

4 2
1 3
2 4

4 2
1 4
2 4

4 2
1 4
2 4

4 2
1 4
2 4

4 2
1 4
2 4

*/

/*
When you walk through a storm
Hold your head up high
And don't be afraid of the dark
At the end of the storm
There's a golden sky
And the sweet silver song
of the lark
Walk on, through the wind
Walk on, through the rain
Though your dreams be tossed
and blown
Walk on, walk on
With hope in your heart
And you'll never walk alone
YNWA
*/

//hell_hacker
//IT TAKES EVERYTHING and IT IS NOT LUCK
//PICK ME LAST -- COME OUT OF N^WHERE

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define fo(i,n) for(i=0;i<n;++i)
#define forr(i,n) for(i=n-1;i>=0;--i)

#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define yolo "debug_statement"

typedef long long int ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

const ll inf = 1e9;
const ld eps = 1e-9;
const ld pi=acos(-1);
const ll mod=1000000007;

ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

#if DEBUG && !ONLINE_JUDGE

    #define debug(args...)     (Debugger()) , args

    class Debugger
    {
        public:
        Debugger(const std::string& _separator = ", ") :
        first(true), separator(_separator){}

        template<typename ObjectType>
        Debugger& operator , (const ObjectType& v)
        {
            if(!first)
                std::cerr << separator;
            std::cerr << v;
            first = false;
            return *this;
        }
        ~Debugger() {  std::cerr << endl;}

        private:
        bool first;
        std::string separator;
    };

    template <typename T1, typename T2>
    inline std::ostream& operator << (std::ostream& os, const std::pair<T1, T2>& p)
    {
        return os << "(" << p.first << ", " << p.second << ")";
    }

    template <typename T1, unsigned long int N>
    inline std::ostream& operator << (std::ostream& os, const std::array<T1, N>& a){
        bool first = true;
        os << "[";
        for(unsigned int i = 0; i < N; i++)
        {
            if(!first)
                os << ", ";
            os << a[i];
            first = false;
        }
        return os << "]";
    }

    template<typename T>
    inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v)
    {
        bool first = true;
        os << "[";
        for(unsigned int i = 0; i < v.size(); i++)
        {
            if(!first)
                os << ", ";
            os << v[i];
            first = false;
        }
        return os << "]";
    }

    template<typename T>
    inline std::ostream &operator << (std::ostream & os,const std::set<T>& v)
    {
        bool first = true;
        os << "[";
        for (typename std::set<T>::const_iterator iii = v.begin(); iii != v.end(); ++iii)
        {
            if(!first)
                os << ", ";
            os << *iii;
            first = false;
        }
        return os << "]";
    }

    template<typename T1, typename T2>
    inline std::ostream &operator << (std::ostream & os,const std::map<T1, T2>& v)
    {
        bool first = true;
        os << "[";
        for (typename std::map<T1, T2>::const_iterator iii = v.begin(); iii != v.end(); ++iii)
        {
            if(!first)
                os << ", ";
            os << *iii ;
            first = false;
        }
        return os << "]";
    }

#else
    #define debug(args...)                  // Just strip off all debug tokens
#endif

// typedef struct{
// 	ll b, e;
// }helik;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	int i, j, n, m;
	ll x, y;
	cin >> n >> m;
	int arr[n] = {0};

	memset(arr,-1,sizeof(arr));

	vector<pair<ll,ll>>op;

	ll mx = 123123123123;

	fo(i,m){
		cin >> x >> y;
		x--;y--;
		mx = min(mx,y-x+1);
		op.pb({y-x+1,x});
	}

	cout << mx << endl;

    // mx--;

	sort(all(op));

	// for(auto it: op)cout << it << endl;return 0;

	for(i=0;i<n;++i)
		arr[i] = 100000000;

    for(auto it: op){
        ll ct = 0;
        ll kitne = it.fi;
        ll pos = it.se;
        while(kitne > 0 && pos < n){
            //cout << pos << endl;
            if(arr[pos] >= 100000000){
                arr[pos++] = ct;
                ct++;
                ct = min(mx-1,ct);
                kitne--;
            }
            else{
                kitne = kitne - (mx - arr[pos]);
                pos = pos + mx - arr[pos];
            }
            // for(i=0;i<n;++i)cout << arr[i] << " ";
            // cout << endl;
        }
    }

	for(i=0;i<n;++i)cout << arr[i] << " ";
	cout << endl;

    return 0;
}