Codeforces Round 381 (Div. 2)
C
Alyona and mex
Codeforces
未评级
原题
← BD →
翻译中…

Alyona's mother wants to present an array of $*n*$ non-negative integers to Alyona. The array should be special.

翻译中…

Alyona is a capricious girl so after she gets the array, she inspects $*m*$ of its subarrays. Subarray is a set of some subsequent elements of the array. The $*i*$-th subarray is described with two integers $*l*_{*i*}$ and $*r*_{*i*}$, and its elements are $*a*[*l*_{*i*}], *a*[*l*_{*i*} + 1], ..., *a*[*r*_{*i*}]$.

翻译中…

Alyona is going to find mex for each of the chosen subarrays. Among these $*m*$ mexes the girl is going to find the smallest. She wants this minimum mex to be as large as possible.

翻译中…

You are to find an array $*a*$ of $*n*$ elements so that the minimum mex among those chosen by Alyona subarrays is as large as possible.

翻译中…

The mex of a set $*S*$ is a minimum possible non-negative integer that is not in $*S*$.

翻译中…

Input

翻译中…

The first line contains two integers $*n*$ and $*m*$ ($1 ≤ *n*, *m* ≤ 10^{5}$).

翻译中…

The next $*m*$ lines contain information about the subarrays chosen by Alyona. The $*i*$-th of these lines contains two integers $*l*_{*i*}$ and $*r*_{*i*}$ ($1 ≤ *l*_{*i*} ≤ *r*_{*i*} ≤ *n*$), that describe the subarray $*a*[*l*_{*i*}], *a*[*l*_{*i*} + 1], ..., *a*[*r*_{*i*}]$.

翻译中…

Output

翻译中…

In the first line print single integer — the maximum possible minimum mex.

翻译中…

In the second line print $*n*$ integers — the array $*a*$. All the elements in $*a*$ should be between $0$ and $10^{9}$.

翻译中…

It is guaranteed that there is an optimal answer in which all the elements in $*a*$ are between $0$ and $10^{9}$.

翻译中…

If there are multiple solutions, print any of them.

翻译中…

Note

翻译中…

The first example: the mex of the subarray $(1, 3)$ is equal to $3$, the mex of the subarray $(2, 5)$ is equal to $3$, the mex of the subarray $(4, 5)$ is equal to $2$ as well, thus the minumal mex among the subarrays chosen by Alyona is equal to $2$.

翻译中…

样例

Input #1
5 3
1 3
2 5
4 5
Output #1
2
1 0 2 1 0
InputCopy OutputCopy
Input #2
4 2
1 4
2 4
Output #2
3
5 2 0 1
InputCopy OutputCopy
题目信息
题号
740C
时间限制
2 s
内存限制
256 MB

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。