#include using namespace std; typedef long long int64; int main() { int64 D, Q, A[30000], B[30000]; vector< int64 > nums; int64 touch[600000] = {}; scanf("%lld %lld", &D, &Q); for(int i = 0; i < Q; i++) { scanf("%lld %lld", &A[i], &B[i]); nums.push_back(A[i] - 1); nums.push_back(A[i]); nums.push_back(B[i]); nums.push_back(B[i] + 1); } sort(begin(nums), end(nums)); nums.erase(unique(begin(nums), end(nums)), end(nums)); for(int i = 0; i < Q; i++) { A[i] = lower_bound(begin(nums), end(nums), A[i]) - begin(nums); B[i] = lower_bound(begin(nums), end(nums), B[i]) - begin(nums); } int64 ret = 0; for(int i = 0; i < Q; i++) { for(int64 j = A[i]; j <= B[i]; j++) touch[j] = true; int64 latte = A[i], malta = B[i]; while(latte >= 0 && touch[latte]) --latte; while(malta < nums.size() && touch[malta]) ++malta; ret = max(ret, nums[malta - 1] - nums[latte + 1] + 1); printf("%lld\n", ret); } }