#include <iostream>
#include <cstdlib>
#include <fstream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <math.h>
#include <stack>
#include <queue>
#include <list>
#include <limits.h>
#include <time.h>
#include <iterator>

#pragma comment(linker, "/STACK:167772160")

using namespace std;

int x[1111];
int len[1111];
int ok[1111];
bool can[1111];
int n, k;

int dfs(int v, int dist, bool good){
	if(v == k) good = 0;
	if(!good) can[v] = 1;
	if(!x[v]){
		len[v] = max(dist + 1, len[v]);
		return dist+1;
	}
//	dfs();
	return len[v] = max(dfs(x[v], dist+1, good), len[v]);
}
int main(){
    //ifstream cin("in.txt");

	cin >> n >> k;
	for(int i=1; i<=n; i++)
		cin >> x[i];
	for(int i=1; i<=n; i++){
		dfs(i, 0, 1);
	}
	//for(int i=1; i<=n; i++) cout << len[i] << " "; cout << endl;

	vector <int> xx;
	int dist = 0;
	int v = k;
	while(v){
		dist++;
		v = x[v];
	}
	for(int i=1; i<=n; i++)
		if(!can[i] && !x[i]) xx.push_back(len[i]);

	int was[1111] = {};
	set <int> ans;
	for(int i=0; i<xx.size(); i++) ans.insert(xx[i] + dist);
	ans.insert(dist);
	was[0] = 1;
	for(int i=0; i<xx.size(); i++)
		for(int j=n; j+1; j--)
			if(was[j] && j + xx[i] + dist <= n){
				was[j + xx[i]] = 1;
				ans.insert(j + xx[i] + dist);
			}
			for(set <int>::iterator it = ans.begin(); it != ans.end(); it++) cout << (*it) << endl;
    return 0;
}


//#include "stdafx.h"
#include <iostream>
#include <vector>
using namespace std;
int par[1010];
int cnt[1010];
bool ba[1010];
vector<int> v;
int n, m, k;
void init(){
    for (int i = 0; i <= n; i++) par[i] = i;
}
int getPar(int a){
    if (par[a] == a) return a;
    else return par[a] = getPar(par[a]);
}
void merge(int a, int b){
    int pa = getPar(a), pb = getPar(b);
    par[pa] = pb;
}
void countPar(){
    for (int i = 1; i <= n; i++){
        cnt[getPar(i)]++;
        if (!ba[par[i]]){
            ba[par[i]] = true;
            v.push_back(par[i]);
        }
    }
}
int gDepth(int a){
    if (par[a] == a) return 1;
    return gDepth(par[a]) + 1;
}
int main(){
    cin >> n >> m;
    init();
    for (int i = 1; i <= n; i++){
        int a;
        cin >> a;
        if (a == 0) continue;
        par[i] = a;
    }
    k = gDepth(m);
    countPar();
    memset(ba, 0, sizeof(ba));
    ba[k] = true;
    cout << k << '\n';
    int l = v.size();
    for (int i = 0; i < l; i++) cout << v[i] << ' ' << cnt[v[i]] << '\n';
    for (int i = 0; i < l; i++){
        for (int j = n; j > 0; j--){
            if (v[i] != par[m] && ba[j - cnt[v[i]]]) ba[j] = true;
        }
    }
    for (int i = 1; i <= n; i++) if (ba[i]) cout << i << '\n';
}


//#include "stdafx.h"
#include <iostream>
#include <vector>
using namespace std;
int par[1010];
int cnt[1010];
bool ba[1010];
vector<int> v;
int n, m, k;
void init(){
    for (int i = 0; i <= n; i++) par[i] = i;
}
int getPar(int a){
    if (par[a] == a) return a;
    else return par[a] = getPar(par[a]);
}
void merge(int a, int b){
    int pa = getPar(a), pb = getPar(b);
    par[pa] = pb;
}
void countPar(){
    for (int i = 1; i <= n; i++){
        cnt[getPar(i)]++;
        if (!ba[par[i]]){
            ba[par[i]] = true;
            v.push_back(par[i]);
        }
    }
}
int gDepth(int a){
    if (par[a] == a) return 1;
    return gDepth(par[a]) + 1;
}
int main(){
    cin >> n >> m;
    init();
    for (int i = 1; i <= n; i++){
        int a;
        cin >> a;
        if (a == 0) continue;
        merge (i, a);
    }
    k = gDepth(m);
    countPar();
    memset(ba, 0, sizeof(ba));
    ba[k] = true;
    int l = v.size();
    for (int i = 0; i < l; i++){
        for (int j = n; j > 0; j--){
            if (v[i] != par[m] && ba[j - cnt[v[i]]]) ba[j] = true;
        }
    }
    for (int i = 1; i <= n; i++) if (ba[i]) cout << i << '\n';
}


//#include "stdafx.h"
#include <iostream>
#include <vector>
using namespace std;
int par[1010];
int cnt[1010];
bool ba[1010];
vector<int> v;
int n, m, k;
void init(){
    for (int i = 0; i <= n; i++) par[i] = i;
}
int getPar(int a){
    if (par[a] == a) return a;
    else return par[a] = getPar(par[a]);
}
void merge(int a, int b){
    int pa = getPar(a), pb = getPar(b);
    par[pa] = pb;
}
void countPar(){
    for (int i = 1; i <= n; i++){
        cnt[getPar(i)]++;
        if (!ba[par[i]]){
            ba[par[i]] = true;
            v.push_back(par[i]);
        }
    }
}
int gDepth(int a){
    if (par[a] == a) return 1;
    return gDepth(par[a]) + 1;
}
int main(){
    cin >> n >> m;
    init();
    for (int i = 1; i <= n; i++){
        int a;
        cin >> a;
        if (a == 0) continue;
        par[i] = a;
    }
    k = gDepth(m);
    countPar();
    memset(ba, 0, sizeof(ba));
    ba[k] = true;
    int l = v.size();
    for (int i = 0; i < l; i++){
        for (int j = n; j > 0; j--){
            if (v[i] != par[m] && j - cnt[v[i]] > 0 && ba[j - cnt[v[i]]]) ba[j] = true;
        }
    }
    for (int i = 1; i <= n; i++) if (ba[i]) cout << i << '\n';
}


//#include "stdafx.h"
#include <iostream>
#include <vector>
using namespace std;
int par[1010];
int cnt[1010];
bool ba[1010];
vector<int> v;
int n, m, k;
void init(){
    for (int i = 0; i <= n; i++) par[i] = i;
}
int getPar(int a){
    if (par[a] == a) return a;
    else return par[a] = getPar(par[a]);
}
void merge(int a, int b){
    int pa = getPar(a), pb = getPar(b);
    par[pa] = pb;
}
void countPar(){
    for (int i = 1; i <= n; i++){
        cnt[getPar(i)]++;
        if (!ba[par[i]]){
            ba[par[i]] = true;
            v.push_back(par[i]);
        }
    }
}
int gDepth(int a){
    if (par[a] == a) return 1;
    return gDepth(par[a]) + 1;
}
int main(){
    cin >> n >> m;
    init();
    for (int i = 1; i <= n; i++){
        int a;
        cin >> a;
        if (a == 0) continue;
        par[i] = a;
    }
    k = gDepth(m);
    countPar();
    memset(ba, 0, sizeof(ba));
    ba[k] = true;
    int l = v.size();
    for (int i = 0; i < l; i++){
        for (int j = n; j > 0; j--){
            if (v[i] != par[m] && ba[j - cnt[v[i]]]) ba[j] = true;
        }
    }
    for (int i = 1; i <= n; i++) if (ba[i]) cout << i << '\n';
}


#include<iostream>
#include<cstdio>
#include<string>
#include<set>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<queue>
using namespace std;

const int sz = 1003;
int a[sz], can[sz][2], l[sz];
bool _root[sz];
vector<int> w;

int dfs(int v)
{
    if (a[v] == 0)
        return l[v] = 1;
    return l[v] = dfs(a[v]) + 1;
}

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "rt", stdin);
        freopen("output.txt", "wt", stdout);
    #endif

    int n, x, XL;
    cin >> n >> x;

    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        _root[a[i]] = 1;
    }
    for (int i = 1; i <= n; i++)
        if (!_root[i])
        {
            int lx = l[x];
            int L = dfs(i);
            if (lx != l[x])
            {
                XL = l[x];
                continue;
            }
            w.push_back(L);
        }

    int k = 0;
    can[0][0] = 1;

    for (int i = 0; i < w.size(); i++)
    {
        for (int j = 0; j < sz; j++)
            if (can[j][k])
            {
                can[j + w[i]][1 - k] = 1;
                can[j][1 - k] = 1;
            }
        k = 1 - k;
    }
    for (int i = 0; i < sz; i++)
        if (can[i][k])
            cout << i + XL << endl;

}


#pragma comment(linker, "/STACK:66777216")
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <utility>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <memory.h>
#include <assert.h>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <cmath>
#include <ctime>
#include <queue>
#pragma hdrstop

using namespace std;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define y0 __MY_Y0__
#define y1 __MY_Y1__
#define yn __MY_YN__
#define hash __MY_HASH__
#define prev __MY_PREV__
#define next __MY_NEXT__
#define less __MY_LESS__
#define div __MY_DIV__
#define sz(a) (int)a.size()
#define fill(a, x) memset (a, x, sizeof(a))

#ifdef _DEBUG
	#define Eo(x) {cout << "# " << #x << " = " << (x) << endl;}
	#define E(x) {cout << "# " << #x << " = " << (x) << " ";}
	#define Ou(x) {cout << "# " << (x) << endl;}
	#define OK {cout << "# OK    Line : " << __LINE__ << endl;}
#else
	#define Eo(x)
	#define E(x)
	#define Ou(x)
	#define OK
#endif

#ifdef WIN32
	#define LLD "%I64d"
#else
	#define LLD "%lld"
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

inline void sIO() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
}
inline void iIO() {freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);}
inline void fIO(string fn) {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin); freopen ("output.txt", "w", stdout);
#else
	freopen((fn + ".in").c_str(), "r", stdin); freopen((fn + ".out").c_str(), "w", stdout);
#endif
}
inline void TM() {
#ifdef _DEBUG
	cout << endl << "# Time: " << clock() / 1000. << endl;
#endif
}
inline void swap(short& a, short& b) {b ^= a ^= b ^= a;}
inline void swap(int& a, int& b) {b ^= a ^= b ^= a;}
inline void swap(char& a, char& b) {b ^= a ^= b ^= a;}
inline void swap(ll& a, ll& b) {b ^= a ^= b ^= a;}
template<class T> inline T abs(T x) {return x < 0 ? -x : x;}
template<class T> inline T sqr(T x) {return x * x;}
template<class T> inline T min(T& a, T& b) {return a < b ? a : b;}
template<class T> inline T max(T& a, T& b) {return a > b ? a : b;}
template<class T> inline T gcd(T a, T b) {if (a < b) swap(a, b); while (b) {a %= b; swap(a, b);} return a;}
template<class T> inline T lcm(T a, T b) {return a / gcd(a, b) * b;}
template<class T> inline bool isPrime(T n) {if (n < 2) return false; T kk = (T)sqrt(n + 0.); for (T i = 2; i <= kk; ++i) if (!(n % i)) return false; return true;}
template<class T> inline string toa(T x) {stringstream ss; ss << x; string ret; ss >> ret; return ret;}
template<class T> inline T ppow(T a, ll b) {T ret = 1; while (b) {if (b & 1) ret *= a; a *= a; b >>= 1;} return ret;}
template<class T> inline T ppow(T a, ll b, ll md) {T ret = 1; a %= md; while (b) {if (b & 1) ret = ret * a % md; a = a * a % md; b >>= 1;} return ret % md;}
inline int toi(string s) {stringstream ss; ss << s; int ret; ss >> ret; return ret;}
inline ll tol(string s) {stringstream ss; ss << s; ll ret; ss >> ret; return ret;}
inline int Random() {return ((rand() << 16) | rand());}
inline int Random(int l, int r) {if (l == r) return l;return Random() % (r - l) + l;}
inline char upperCase(char ch) {return (ch >= 'a' && ch <= 'z') ? ch^32 : ch;}
inline char lowerCase(char ch) {return (ch >= 'A' && ch <= 'Z') ? ch^32 : ch;}
inline string upperCase(string s) {int ls = s.length(); for (int i = 0; i < ls; ++i) if (s[i] >= 'a' && s[i] <= 'z') s[i] ^= 32; return s;}
inline string lowerCase(string s) {int ls = s.length(); for (int i = 0; i < ls; ++i) if (s[i] >= 'A' && s[i] <= 'Z') s[i] ^= 32; return s;}
inline int dig(char ch) {return ch - 48;}
inline bool isAlpha(char ch) {return (ch >= 'A' && ch <= 'Z' || ch >= 'a' && ch <= 'z');}
inline bool isDigit(char ch) {return (ch >= '0' && ch <= '9');}
inline bool isLowerCase(char ch) {return (ch >= 'a' && ch <= 'z');}
inline bool isUpperCase(char ch) {return (ch >= 'A' && ch <= 'Z');}

int __;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const int MD = 1000000007;

int n, k, a[1111], color[1111], curcol, offset, cnt[1111];
bool w[4444];

int dfs(int v) {
	if (!a[v]) return color[v] = ++curcol;
	if (color[a[v]] > -1) return color[v] = color[a[v]];
	return color[v] = dfs(a[v]);
}

int gogo(int v) {
	if (!a[v]) return 1;
	return 1 + gogo(a[v]);
}

int main() {
	sIO();
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; ++i)
		scanf("%d", a + i);
	fill(color, -1), curcol = -1, offset = gogo(k), dfs(k);
	for (int i = 1; i <= n; ++i)
		if (color[i] == -1) dfs(i);
	fill(cnt, 0);
	for (int i = 1; i <= n; ++i)
		++cnt[color[i]];
	w[0] = true;
	for (int i = 1; i <= curcol; ++i)
		for (int j = n; j >= 0; --j)
			if (w[j]) w[j + cnt[i]] = true;
	for (int i = 0; i <= n; ++i)
		if (w[i]) printf("%d\n", i + offset);
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <set>
#include <map>

using namespace std;

struct DSU {
	int id[10000];
	map<int, int> cc;
	DSU(int n) {
		for (int i = 0; i < n; i++) {
			id[i] = i;
			cc.insert(make_pair(i, 1));
		}
	}
	int find(int a) {
		return a == id[a] ? a : id[a] = find(id[a]);
	}
	void merge(int a, int b) {
		int pa = find(a), pb = find(b);
		if (pa == pb)
			return;
		int rs = cc[pa] + cc[pb];
		cc.erase(pa);
		cc.erase(pb);
		if (rand() & 1) {
			id[pa] = pb;
			cc.insert(make_pair(pb, rs));
		} else {
			id[pb] = pa;
			cc.insert(make_pair(pa, rs));
		}
	}
	set<int> pos() {
		set<int> res;
		for (map<int, int>::iterator i = cc.begin(); i != cc.end(); i++) {
			vector<int> step;
			for (set<int>::iterator j = res.begin(); j != res.end(); j++)
				step.push_back(*j + i->second);
			for (vector<int>::iterator j = step.begin(); j != step.end(); j++)
				res.insert(*j);
			res.insert(i->second);
		}
		return res;
	}
};

int n, b;
int a[1010];

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	scanf("%d%d", &n, &b);
	b--;
	DSU dsu(n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		if (a[i])
			dsu.merge(i, a[i] - 1);
	}
	int c = 1, p = a[b];
	for (; p; c++)
		p = a[p - 1];
	dsu.cc.erase(dsu.find(b));
	set<int> res = dsu.pos();
	printf("%d\n", c);
	for (set<int>::iterator i = res.begin(); i != res.end(); i++)
		printf("%d\n", *i + c);
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;

int n, x, lenx;
int za[1005], per[1005];
int len[1005], cnt;
int is[1005];
vector<int> rez, dob;

int main()
{	int i, j, t, f;

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	scanf("%d %d", &n, &x);
	for(i=1; i<=n; ++i)
	{
		scanf("%d", &t);
		per[i] = t;
		za[t] = i;
	}
	for(i=1; i<=n; ++i)
	{
		if(per[i] == 0)
		{
			t=1;
			if(i == x)
			{
				lenx = t;
				continue;
			}
			j = i; f=0;
			while(za[j])
			{
				++t;
				j = za[j];
				if(j == x)
				{
					lenx = t;
					f=1;
					break;
				}
			}
			if(!f)
			{
				len[cnt] = t;
				cnt++;
			}
		}
	}

	/*for(i=0; i<cnt; ++i)
		printf("%d ", len[i]);
	*/

	rez.push_back(lenx);
	is[lenx] = 1;
	for(i=0; i<cnt; ++i)
	{
		for(j=0; j<rez.size(); ++j)
		{
			t = len[i] + rez[j];
			if(t<=n && !is[t])
			{
				is[t] = 1;
				dob.push_back(t);
			}
		}
		for(j=0; j<dob.size(); ++j)
			rez.push_back(dob[j]);
		dob.clear();
	}

	/*for(i=0; i<rez.size(); ++i)
		printf("%d ", rez[i]);
	*/
	for(i=1; i<=n; ++i)
		if(is[i])
			printf("%d\n", i);

	return 0;
}


#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import collections

def find(parents, i):
    if parents[i] == i:
        return i
    result = find(parents, parents[i])
    parents[i] = result
    return result

def union(parents, i, j):
    i, j = find(parents, i), find(parents, j)
    parents[i] = j

if __name__ == '__main__':
    n, x = map(int, input().split())
    a = {i + 1: int(ai) for i, ai in enumerate(input().split())}

    parents = {i: i for i in a}
    x_order = 1
    x_current = x
    while a[x_current] != 0:
        x_order += 1
        x_current = a[x_current]

    for source, target in a.items():
        if target != 0:
            union(parents, source, target)

    del a

    x_representative = find(parents, x)

    sizes = collections.Counter()
    for i in parents:
        i_representative = find(parents, i)
        if i_representative != x_representative:
            sizes[i_representative] += 1

    del parents

    adds = collections.Counter()
    for size in sizes.values():
        adds[size] += 1

    del sizes

    sieve = {0: 1}
    for add, count in adds.items():
        sieve_update = {}
        for i, j in sieve.items():
            if j != 0:
                for k in range(1, count + 1):
                    if i + add * k <= n:
                        sieve_update[i + add * k] = 1
        sieve.update(sieve_update)

    del adds

    for position, value in sorted(sieve.items()):
        if value:
            print(position + x_order)


import sys
sys.setrecursionlimit(100000)
def solve():
    n, x, = rv()
    x -= 1
    a, = rl(1)
    a = [val - 1 for val in a]
    nxt = [True] * n
    index = [-1] * n
    for i in range(len(a)):
        index[i] = get(i, a, nxt)
    curindex = index[x] - 1
    others = list()
    for i in range(n):
        if not bad(i, a, x) and nxt[i]:
            others.append(index[i])
    others.sort()
    possible = [False] * (n + 1)
    possible[0] = True
    for val in others:
        pcopy = list(possible)
        for i in range(n + 1):
            if possible[i]:
                both = i + val
                if both < n + 1:
                    pcopy[both] = True
        possible = pcopy
    res = list()
    for i in range(n + 1):
        if possible[i]:
            comb = i + curindex
            if comb < n:
                res.append(comb)
    print('\n'.join(map(str, [val + 1 for val in res])))

def bad(index, a, x):
    if index == x: return True
    if a[index] == x: return True
    if a[index] == -1: return False
    return bad(a[index], a, x)

def get(index, a, nxt):
    if a[index] == -1:
        return 1
    else:
        nxt[a[index]] = False
        return get(a[index], a, nxt) + 1

def prt(l): return print(' '.join(l))
def rv(): return map(int, input().split())
def rl(n): return [list(map(int, input().split())) for _ in range(n)]
if sys.hexversion == 50594544 : sys.stdin = open("test.txt")
solve()


import sys
sys.setrecursionlimit(100000)
def solve():
    n, x, = rv()
    x -= 1
    a, = rl(1)
    a = [val - 1 for val in a]
    nxt = [True] * n
    index = [-1] * n
    for i in range(len(a)):
        index[i] = get(i, a, nxt)
    curindex = index[x] - 1
    others = list()
    for i in range(n):
        if not bad(i, a, x) and nxt[i]:
            others.append(index[i])
    others.sort()
    possible = [False] * (n + 1)
    possible[0] = True
    for val in others:
        pcopy = list(possible)
        for i in range(n + 1):
            if possible[i]:
                both = i + val
                if both < n + 1:
                    pcopy[both] = True
        possible = pcopy
    res = list()
    for i in range(n + 1):
        if possible[i]:
            comb = i + curindex
            if comb < n:
                res.append(comb)
    print('\n'.join(map(str, [val + 1 for val in res])))

def bad(index, a, x):
    if index == x: return True
    if a[index] == -1: return False
    return bad(a[index], a, x)

def get(index, a, nxt):
    if a[index] == -1:
        return 1
    else:
        nxt[a[index]] = False
        return get(a[index], a, nxt) + 1

def prt(l): return print(' '.join(l))
def rv(): return map(int, input().split())
def rl(n): return [list(map(int, input().split())) for _ in range(n)]
if sys.hexversion == 50594544 : sys.stdin = open("test.txt")
solve()


def f(x, p):
    q = []
    while x:
        q.append(x)
        x = p[x]
    return q
from collections import defaultdict
n, k = map(int, input().split())
t = list(map(int, input().split()))
p = [0] * (n + 1)
for i, j in enumerate(t, 1):
    p[j] = i
p = [f(i, p) for i, j in enumerate(t, 1) if j == 0]
s = defaultdict(int)
for i in p:
    if k in i: t = {i.index(k) + 1}
    else: s[len(i)] += 1
s = [list(range(i, k * i + 1, i)) for i, k in s.items()]
for q in s:
    t |= {x + y for x in q for y in t}
print('\n'.join(map(str, sorted(list(t)))))


n, x = map(int, input().split())
link1 = list(map(int, input().split()))
link2 = [0] * (n + 1)
for i, v in enumerate(link1, 1):
    if v != 0:
        link2[v] = i

table = [False] * n
table[0] = True
for i, v in enumerate(link1, 1):
    if v == 0:
        len = 0
        flag = False
        now = i
        while now:
            len += 1
            if now == x:
                flag = True
                pos = len
            now = link2[now]
        if not flag:
            for j in reversed(range(n - len)):
                if table[j]:
                    table[j + len] = True
for i in range(n):
    if table[i]:
        print(i + pos)


#! ruby -Ku
# -*- coding: utf-8 -*-
# file = open("input.txt")
# total_sb = file.gets.split.map(&:to_i)
# follow = file.gets.split.map(&:to_i) # [i]+1 follows follow[i]
total_sb = gets.split.map(&:to_i)
follow = gets.split.map(&:to_i) # [i]+1 follows follow[i]

num_total = total_sb.shift
sb_num = total_sb.shift

chain = Struct.new("Chain", :length, :check)
chains = Array::new
num_total.times{chains << chain.new(1, false)}

# make chains
def trace_chain(follow, chains, index, length)
  if follow[index] == 0
    chains[index].length = length + 1
    return length + 1
  else
    chains[index].length = trace_chain(follow, chains, follow[index]-1, length+1)
    return chains[index].length
  end
end
# check if SB is contained
def check_sb_contains(follow, chains, index, check, sb_num)
  if sb_num-1 == index
    check = true
  end
  if follow[index] == 0
    chains[index].check = check
    return check
  else
    chains[index].check = check_sb_contains(follow, chains, follow[index]-1, check, sb_num)
    return chains[index].check
  end
end

followed = Array::new
num_total.times {followed << false}
# who is the last in each chain
follow.each do |x|
  if x != 0
    followed[x-1] = true
  end
end

# number of chain before smart beaver
offset_smart_beaver = trace_chain(follow, chains, sb_num-1, 0)
# puts offset_smart_beaver

# count each length
num_total.times do |i|
  if followed[i] == false
    trace_chain(follow, chains, i, 0)
    check_sb_contains(follow, chains, i, false, sb_num)
  end
end

# count chains number
chains_bin = Array::new
num_total.times do |i|
  if followed[i] == false && !chains[i].check
    chains_bin << chains[i].length
  end
end
chains_bin.sort!
# puts chains_bin

# count chain pattern by dp
dp_table = Array::new
dp_table << 1
chains_bin.each do |bin|
  1000.downto(0) do |i|
    if dp_table[i] != nil
      dp_table[i+bin] = 1
    end
  end
end
# puts dp_table

1000.times do |i|
  if dp_table[i] != nil
    puts i + offset_smart_beaver
  end
end


require 'set'

n, x = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

s = Set.new

a.each do |ai|
		s.add(ai) if ai > 0
end

sum = 1
dp = Array.new(1001,false)
dp[0] = true

a.each_with_index do |ai,i1|
	i = i1 + 1
	next if s.member?(i)
	flag = false
	acc = 0
	while i > 0
		sum += 1 if flag
		flag ||= i == x
		acc += 1
		i = a[i-1]
	end
	next if flag
	1000.downto(0) do |j|
		next if not dp[j]
		dp[j+acc] ||= dp[j]
	end
end

0.upto(1000) do |i|
	next if not dp[i]
	puts(sum + i)
end


I=lambda:map(int,raw_input().split())
n,x=I()
a=[0]+I()
v=[0]*(n+1)
r={0}
for i in range(n+1):v[a[i]]=i
for i in range(1,n+1):
 if a[i]<1:
	t=1
	while i:
	 if i==x:Z=t;break
	 t+=1;i=v[i]
	else:r|={j+t-1for j in r}
for i in sorted(r):print i+Z


r=lambda:map(int,raw_input().split())
n,x=r()
a=[0]+r()
v=[0]*(n+1)
for i in range(n+1):
    if a[i]:
        v[a[i]] = i
r={0}
X=1
for i in range(1,n+1):
    if a[i] < 1:
        k = 1
        z = i
        f=0
        while z:
            if z == x:
                X=k;f=1
                break
            z = v[z]
            k+=1
        if not f: r|={j + k - 1 for j in r}

print '\n'.join(`i + X` for i in sorted(list(r)))


using System;
using System.Collections;
using System.Collections.Generic;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().solve();
        return 0;
    }

    void solve()
    {
        Scanner cin = new Scanner();

        int n = cin.nextInt();
        int x = cin.nextInt() - 1;
        int[] a = new int[n];
        int[] count = new int[n];
        int[] child = new int[n];
        int[] parent = new int[n];
        for (int i = 0; i < n; i++)
        {
            a[i] = cin.nextInt() - 1;
        }
        bool[] check = new bool[n + 2000];
        check[0] = true;

        for (int i = 0; i < n; i++)
        {
            int now = i;
            while (a[now] != -1)
            {
                count[i]++;
                now = a[now];
            }
            parent[i] = now;
            child[now] = Math.Max(child[now], count[i] + 1);
        }

        for (int i = 0; i < n; i++)
        {
            if (count[i] != 0) continue;
            if (parent[x] == i) continue;
            for (int j = n - 1; j >= 0; j--)
            {
                if (check[j]) check[j + child[i]] = true;
            }
        }
        for (int i = 0; i < check.Length; i++)
        {
            if (check[i]) Console.WriteLine(i + count[x] + 1);
        }
    }

}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        s = Console.ReadLine().Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }
}


package main

import (
	"fmt"
)

func main() {
	var n, x int
	fmt.Scanf("%d %d\n", &n, &x)
	prev := make([]int, n + 1)
	next := make([]int, n + 1)
	for i := 1;i <= n;i ++ {
		fmt.Scanf("%d", &prev[i])
		if prev[i] != 0 {
			next[prev[i]] = i
		}
	}

	queue := make([]int, 0, n)
	var wisePos int

	for i := 1;i <= n;i ++ {
		var isWise bool
		var length int
		if prev[i] == 0 {
			for cur := i; cur != 0; cur, length = next[cur], length + 1 {
				if x == cur {
					isWise = true
					wisePos = length + 1
					break
				}
			}
			if !isWise {
				queue = append(queue, length)
			}
		}
	}

	dp := make([]bool, n + 1)
	dp[0] = true
	for i := 0;i < len(queue);i ++ {
		for j := len(dp) - 1;j >= queue[i];j -- {
			if dp[j - queue[i]] {
				dp[j] = true
			}
		}
	}
	for i := 0;i < len(dp);i ++ {
		if dp[i] {
			fmt.Printf("%d\n", i + wisePos)
		}
	}
}


def put(): return map(int, input().split())

n,x = put()
a = list(put())

parent = list(range(n+1))
for i in range(n):
    if a[i]!=0:
        parent[a[i]] = i+1

cnt = []
z = 0
#print(parent)
for i in range(n):
    if a[i]==0:
        j = i+1
        c = 1
        found = False
        if j==x:
            z=c
            found = True
        while j != parent[j]:
            j = parent[j]
            c+=1
            if j==x:
                z=c
                found = True
        if not found:
            cnt.append(c)

#print(cnt,z)
n,m = len(cnt)+1, sum(cnt)+1
dp = [[0]*(m+1) for i in range(n+1)]
dp[0][0]=1
s = set()
s.add(0)
for i in range(1,n):
    for j in range(m):
        if  j==0 or dp[i-1][j]==1 or (j-cnt[i-1]>=0 and dp[i-1][j-cnt[i-1]]==1) :
            dp[i][j] = 1
            s.add(j)
l = []
for i in s:
    l.append(i+z)

l.sort()
print(*l)


import math
import sys
from bisect import bisect_right, bisect_left, insort_right
from collections import Counter, defaultdict
from heapq import heappop, heappush
from itertools import accumulate, permutations
from sys import stdout

R = lambda: map(int, input().split())
n, s = R()
seq = [0] + list(R())
incm = [0] * (n + 1)
for x in seq:
    if x:
        incm[x] = 1
sz = [0] * (n + 1)
st = []
bs = 1
x = s
while seq[x]:
    bs += 1
    x = seq[x]
for i, x in enumerate(incm):
    foundx = False
    if not x:
        l = i
        while i:
            foundx = foundx or i == s
            sz[l] += 1
            i = seq[i]
        if seq[l] and not foundx:
            st.append(sz[l])
nz = seq.count(0) - 1 - len(st) - 1
pos = [0] * (n + 1)
for p in st:
    for i in range(n + 1):
        if bs + i + p < n + 1 and pos[bs + i]:
            pos[bs + i + p] = 1
    pos[bs + p] = 1
rp = [0] * (n + 1)
rp[bs] = 1
if bs + nz + 1 < n + 1:
    rp[bs + nz + 1] = -1
for i in range(n + 1):
    if pos[i]:
        rp[i] += 1
        if i + nz + 1 < n + 1:
            rp[i + nz + 1] -= 1
for i in range(1, n + 1):
    rp[i] += rp[i - 1]
for i in range(1, n + 1):
    if rp[i]:
        print(i)


import math
import sys
from bisect import bisect_right, bisect_left, insort_right
from collections import Counter, defaultdict
from heapq import heappop, heappush
from itertools import accumulate, permutations
from sys import stdout

R = lambda: map(int, input().split())
n, s = R()
seq = [0] + list(R())
incm = [0] * (n + 1)
for x in seq:
    if x:
        incm[x] = 1
sz = [0] * (n + 1)
st = []
bs = 1
x = s
while seq[x]:
    bs += 1
    x = seq[x]
for i, x in enumerate(incm):
    foundx = False
    if not x:
        l = i
        while i:
            foundx = foundx or i == s
            sz[l] += 1
            i = seq[i]
        if seq[l] and not foundx:
            st.append(sz[l])
nz = seq.count(0) - 1 - len(st) - 1
pos = [0] * (n + 1)
for p in st:
    for i in range(n, -1, -1):
        if bs + i + p < n + 1 and pos[bs + i]:
            pos[bs + i + p] = 1
    pos[bs + p] = 1
rp = [0] * (n + 1)
rp[bs] = 1
if bs + nz + 1 < n + 1:
    rp[bs + nz + 1] = -1
for i in range(n + 1):
    if pos[i]:
        rp[i] += 1
        if i + nz + 1 < n + 1:
            rp[i + nz + 1] -= 1
for i in range(1, n + 1):
    rp[i] += rp[i - 1]
for i in range(1, n + 1):
    if rp[i]:
        print(i)


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ld double
#define ll long long
#define all(x) x.begin(),x.end()
const int mod=998244353;
#define fi first
#define se second
#define Dracarys  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define inf (ll)1e16

ll power(ll x,ll y,ll p){
    ll res=1;
    x = x % p;
    while (y > 0){
        if (y & 1)
        res = (res * x) % p;
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}
bitset<1000005> prime;
void sieve(int n){
    prime.flip();
    for (int p=2; p*p<=n; p++){
        // If prime[p] is not changed, then it is a prime
        if (prime[p] == 1){
            for (int i=p*p; i<=n; i += p)prime[i] = 0;
        }
    }
    prime[1]=0;
}

int main() {

	Dracarys

    ll t=1;
    //cin>>t;
    while(t--){
       ll n,m;
       cin>>n>>m;
       vector<ll> v(m+1);

       vector<ll> diff(n+2,0);

       for (ll x,y,i=1;i<=m;i++)
       cin>>x>>y,diff[max(1ll,x)]++,diff[min(y,n)+1]--;

       for (ll i=1;i<=n;i++)
       diff[i]+=diff[i-1];

       for (ll i=1;i<=n;i++){
           if (diff[i]!=1){
               cout<<i<<" "<<diff[i]<<"\n";
               return 0;
           }
       }
       cout<<"OK\n";
    }

    return 0;
}


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

int main()
{
  long long n,m;
  cin>>n>>m;

  long long arr[m][2];
  long long i;

  bool condition1=true;
  bool condition2=true;
  long long count=1,j;

  for(i=0;i<m;i++)
  cin>>arr[i][0]>>arr[i][1];

  if(arr[0][0]!=1)
  cout<<"1 0";

  else
  {
  for(i=0;i<m-1;i++)
    {
      if((arr[i][1]+1)==arr[i+1][0])
      {
        condition1=true;
        condition2=true;
      }

      else if((arr[i][1]+1)<arr[i+1][0])
      {
        condition1=false;
        break;
      }
      else if((arr[i][1]+1)>arr[i+1][0])
      {
        if(arr[i][1]==arr[i+1][0])
        {
            for(j=i+1;j<m;j++)
            {
                if(arr[j][0]==arr[i][1])
                count+=1;
            }
        }

        condition2=false;
        break;
      }
    }

    if(condition1==false)
    cout<<(arr[i][1]+1)<<" 0";

    else if(condition2==false)
    cout<<(arr[i][1])<<" "<<count;

    else if(arr[0][0]==1 && condition1==true && condition2==true && arr[m-1][1]!=n)
    cout<<n<<" 0";

    else if(arr[0][0]==1 && condition1==true && condition2==true && arr[m-1][1]==n)
    cout<<"OK";
  }
}


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

int main()
{
  long long n,m;
  cin>>n>>m;

  long long arr[m][2];
  long long i;

  bool condition1=true;
  bool condition2=true;

  for(i=0;i<m;i++)
  cin>>arr[i][0]>>arr[i][1];

  if(arr[0][0]!=1)
  cout<<"1 0";

  else
  {
  for(i=0;i<m-1;i++)
    {
      if((arr[i][1]+1)==arr[i+1][0])
      {
        condition1=true;
        condition2=true;
      }

      else if((arr[i][1]+1)<arr[i+1][0])
      {
        condition1=false;
        break;
      }
      else if((arr[i][1]+1)>arr[i+1][0])
      {
        condition2=false;
        break;
      }
    }

    if(condition1==false)
    cout<<(arr[i][1]+1)<<" 0";

    else if(condition2==false)
    cout<<(arr[i][1])<<" 2";

    else if(arr[0][0]==1 && condition1==true && condition2==true && arr[m-1][1]!=n)
    cout<<n<<" 0";

    else if(arr[0][0]==1 && condition1==true && condition2==true && arr[m-1][1]==n)
    cout<<"OK";
  }
}


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

int main() {
	int n , m , i , x , y , f=0;
	cin >> n >> m;
	int a[n+1];
	memset(a,0,sizeof(a));
	for(i=1;i<=m;i++){
	    cin >> x >> y;
	    for(int j=x;j<=y;j++){
	        a[j]++;
	    }
	}
	for(i=1;i<=n;i++){
	    if(a[i]!=1){
	        cout << i << " " << a[i] << "\n";
	        f=1;
	        break;
	    }
	}
	if(f==0)
	    cout << "OK\n";
}


#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("-Ofast")
#include <bits/stdc++.h>
using namespace std;

typedef int in;
#define int long long
#define f first
#define s second
#define pb push_back
#define pp push
#define ceil(x) (int)(ceil(x))
const int MAX=1e7;
const int MOD=1e9+7;
const int MAAX=1e18;

int freq[110],n,m;

in main()
{
    int tc=1;
    //scanf("%lld",&tc);
    while(tc--)
    {
        cin>>n>>m;
        for(int i=0;i<m;i++){
        	int x,y;
        	cin>>x>>y;
        	for(int j=x;j<=y;j++){
        		freq[j]++;
        	}
        }
        for(int i=1;i<=n;i++){
        	if(freq[i]!=1){
        		cout<<i<<" "<<freq[i]<<endl;
        		return 0;
        	}
        }
        cout<<"OK\n";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long int n,m;
    cin>>n>>m;
    long long int arr[n]={0};
    for(long long int i=0;i<m;++i)
    {
        long long int start,end;
        cin>>start>>end;
        for(long long int j=start-1;j<=end-1;++j)
        {
            arr[j]++;
        }
    }
    long long int flag=0;
    for(long long int i=0;i<n;++i)
    {
        if(arr[i]!=1)
        {
            cout<<i+1<<" "<<arr[i]<<endl;
            flag=1;
            break;
        }
    }
    if(flag==0)
    {
        cout<<"OK"<<endl;
    }
}


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

int main()
{
    int n,m;
    cin>>n;
    cin>>m;
    int i,j,sum=0;
    int *a=new int[m];
    int* b=new int[m];
    for(i=0;i<m;i++){
            cin>>a[i]>>b[i];
    }
    if(a[0]==1){
    for(i=0;i<m-1;i++){
            if(a[i+1]>b[i]+1){
                cout<<b[i]+1<<" 0"<<endl;
                i=m+1;
            }else if(i<m-1&&a[i+1]==b[i]){
                  j=i+1;
                  sum=2;
                  while(j<m-1&&a[j]==b[j]){
                     if(a[j+1]==b[j]){
                        sum++;
                     }else{
                        j=m-1;
                     }
                     j++;
                  }
                  cout<<b[i]<<" "<<sum<<endl;
                  i=m+1;
            }
    }
    if(b[m-1]==n&&i==m-1){
        cout<<"OK"<<endl;
    }else if(b[m-1]!=n&&i==m-1){
        cout<<b[m-1]+1<<" 0"<<endl;
    }
    }else{
      cout<<"1 0"<<endl;
    }
    //cout << "Hello world!" << endl;
    return 0;
}


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

int main()
{
    int n,m;
    cin>>n;
    cin>>m;
    int i,j,sum=0;
    int *a=new int[m];
    int* b=new int[m];
    for(i=0;i<m;i++){
            cin>>a[i]>>b[i];
    }
    if(a[0]==1){
    for(i=0;i<m-1;i++){
            if(a[i+1]>b[i]+1){
                cout<<b[i]+1<<" 0"<<endl;
                i=m+1;
            }else if(i<m-1&&a[i+1]==b[i]){
                  j=i+1;
                  sum=2;
                  while(j<m-1&&a[j]==b[j]){
                     if(a[j+1]==b[j]){
                        sum++;
                     }else{
                        j=m-1;
                     }
                     j++;
                  }
                  cout<<b[i]<<" "<<sum<<endl;
                  i=m+1;
            }
    }
    if(b[m-1]==n&&i==m-1){
        cout<<"OK"<<endl;
    }else if(b[m-1]!=n){
        cout<<b[m-1]+1<<" 0"<<endl;
    }
    }else{
      cout<<"1 0"<<endl;
    }
    //cout << "Hello world!" << endl;
    return 0;
}


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

int main()
{
    int n,m;
    cin>>n;
    cin>>m;
    int i,j,sum=0;
    int *a=new int[m];
    int* b=new int[m];
    for(i=0;i<m;i++){
            cin>>a[i]>>b[i];
    }
    bool p=true;
    for(i=0;i<m;i++){
       if(a[i]>b[i]||a[i+1]<b[i]||b[i]>n||a[i]>n||m>100||n>100){
          p=false;
         i=m;
       }
    }
    if(p){
    if(a[0]==1){
    for(i=0;i<m-1;i++){
            if(a[i+1]>b[i]+1){
                cout<<b[i]+1<<" 0"<<endl;
                i=m+1;
            }else if(i<m-1&&a[i+1]==b[i]){
                  j=i+1;
                  sum=2;
                  while(j<m-1&&a[j]==b[j]){
                     if(a[j+1]==b[j]){
                        sum++;
                     }else{
                        j=m-1;
                     }
                     j++;
                  }
                  cout<<b[i]<<" "<<sum<<endl;
                  i=m+1;
            }
    }
    if(i==m-1){
        cout<<"OK"<<endl;
    }
    }else{
      cout<<"1 0"<<endl;
    }
    }
    //cout << "Hello world!" << endl;
    return 0;
}


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

int main()
{
    int n,m;
    cin>>n;
    cin>>m;
    int i,j,sum=0;
    int *a=new int[m];
    int* b=new int[m];
    for(i=0;i<m;i++){
            cin>>a[i]>>b[i];
    }
    if(a[0]==1){
    for(i=0;i<m-1;i++){
            if(a[i+1]>b[i]+1){
                cout<<b[i]+1<<" 0"<<endl;
                i=m+1;
            }else if(i<m-1&&a[i+1]==b[i]){
                  j=i+1;
                  sum=2;
                  while(j<m-1&&a[j]==b[j]){
                     if(a[j+1]==b[j]){
                        sum++;
                     }else{
                        j=m-1;
                     }
                     j++;
                  }
                  cout<<b[i]<<" "<<sum<<endl;
                  i=m+1;
            }
    }
    if(i==m-1){
        cout<<"OK"<<endl;
    }
    }else{
      cout<<"1 0"<<endl;
    }
    //cout << "Hello world!" << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,m,i,j,flag=0;
    cin>>n>>m;
    int a[m],b[m],count[n];
    for(i=0;i<m;i++)
    cin>>a[i]>>b[i];
    for(i=0;i<n;i++)
    count[i]=0;
    for(i=0;i<m;i++){
        for(j=a[i]-1;j<=b[i]-1;j++)
        count[j]++;
    }
    for(i=0;i<n;i++){
        if(count[i] != 1){
            cout<<i+1<<" "<<count[i];
            flag=1;
            break;
        }
    }
    if(flag==0)
    cout<<"OK";

}


#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;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long

#ifdef sarthak
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#else
#define trace(...)
#endif

#ifndef sarthak
    #pragma GCC optimize("Ofast")
    #pragma GCC optimize("unroll-loops")
    // #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif

#define foreach(it,ar) for (auto it = ar.begin(); it != ar.end(); it++)
#define fort(i,v) for(auto i:v)
#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define fill(ar,val) rep(i,sizeof(ar)/sizeof(ll)) ar[i]=val
#define fill2(ar,val) rep(i,sizeof(ar)/sizeof(ar[0])) rep(j,sizeof(ar[0])/sizeof(ll)) ar[i][j]=val
#define fill0(ar) memset(ar,0,sizeof(ar))
#define debug(x) cout<<#x<<": "<<x<<endl

#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define sd2(x,y) scanf("%d %d",&x,&y)
#define slld2(x,y) scanf("%lld %lld",&x,&y)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pd2(x,y) printf("%d %d\n",x,y)
#define plld2(x,y) printf("%lld %lld\n",x,y)
#define all(ar) ar.begin(), ar.end()
#define endl '\n'
#define sz(x) (int)x.size()
#define len(x) (int)x.length()

typedef pair<ll, ll> ii;
typedef pair<ii, ll> iii;
typedef vector<ii> vii;
typedef vector<ll> vi;

#define INF 2000000000000000000
#define PI 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679L

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rngb(chrono::steady_clock::now().time_since_epoch().count()); // can give negative values too

void solve()
{
    ll n,m;
    cin >> n >> m;

    ll num[n+1];
    fill0(num);

    rep(i,m)
    {
        ll a,b;
        cin >> a >> b;
        fr(j,a,b)
        {
            num[j]++;
        }
    }

    fr(i,1,n)
    {
        if(num[i]!=1)
        {
            cout << i << " " << num[i] << endl;
            return;
        }
    }

    cout << "OK" << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << fixed;
    cout << setprecision(10);
    #ifdef sarthak
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    ll t = 1;
    // cin >> t;
    while(t--)
    {
        solve();
    }

    #ifdef sarthak
    cerr << "Time elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
    #endif
}


#include<bits/stdc++.h>
using namespace std;
#include<string>
typedef long long int ll;
#define fr ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include<algorithm>
#include<vector>
const long long int maxn = 1e3+2;
const long long int mod = 1e3+2;
int main()
{
	fr
	ll n,m;
	cin>>n>>m;
	map<ll,ll> ma;
	ll a[m],b[m],min=n+1,i,flag=0,f=0;
	for(i=0;i<m;i++)
	{
		cin>>a[i];
	    cin>>b[i];
	    if(i!=0&&b[i-1]+1<a[i]&&flag==0)
		{
			min=b[i-1]+1;
			flag=1;
		}
		if(a[i]==b[i])
		{
			ma[a[i]]++;
		}
		else
		{
	    	ma[a[i]]++;
		    ma[b[i]]++;
	    }
	}
	if(a[0]!=1)
	{
	cout<<"1 0";
	return 0;
	}
	ll rep=m+1;
	for(i=0;i<m;i++)
	{
		if(ma[a[i]]>1)
		{
		   rep=a[i];
		   f=1;
		   break;
		}
		if(ma[b[i]]>1)
		{
			rep=b[i];
			f=1;
			break;
		}
	}
	if(flag==0&&f==0)
	{
		cout<<"OK";
	}
	else
	{
       if(rep>min)
       {
       	  cout<<min<<" 0";
	   }
	   else
	   {
	   	 cout<<rep<<" "<<ma[rep];
	   }
	}
}


#include<bits/stdc++.h>
using namespace std;
#include<string>
typedef long long int ll;
#define fr ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include<algorithm>
#include<vector>
const long long int maxn = 1e3+2;
const long long int mod = 1e3+2;
int main()
{
	fr
	ll n,m;
	cin>>n>>m;
	map<ll,ll> ma;
	ll a[m],b[m],min=n+1,i,flag=0,f=0;
	for(i=0;i<m;i++)
	{
		cin>>a[i];
	    cin>>b[i];
	    if(i!=0&&b[i-1]+1<a[i])
		{
			min=b[i-1]+1;
			flag=1;
		}
		if(a[i]==b[i])
		{
			ma[a[i]]++;
		}
		else
		{
	    	ma[a[i]]++;
		    ma[b[i]]++;
	    }
	}
	if(a[0]!=1)
	{
	cout<<"1 0";
	return 0;
	}
	ll rep=m+1;
	for(i=0;i<m;i++)
	{
		if(ma[a[i]]>1)
		{
		   rep=a[i];
		   f=1;
		   break;
		}
		if(ma[b[i]]>1)
		{
			rep=b[i];
			f=1;
			break;
		}
	}
	if(flag==0&&f==0)
	{
		cout<<"OK";
	}
	else
	{
       if(rep>min)
       {
       	  cout<<min<<" 0";
	   }
	   else
	   {
	   	 cout<<rep<<" "<<ma[rep];
	   }
	}
}


#include<bits/stdc++.h>
using namespace std;
#include<string>
typedef long long int ll;
#define fr ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include<algorithm>
#include<vector>
const long long int maxn = 1e3+2;
const long long int mod = 1e3+2;
int main()
{
	fr
	ll n,m;
	cin>>n>>m;
	map<ll,ll> ma;
	ll a[m],b[m],min=n+1,i,flag=0,f=0;
	for(i=0;i<m;i++)
	{
		cin>>a[i];
	    cin>>b[i];
	    if(i!=0&&b[i-1]+1<a[i])
		{
			min=b[i-1]+1;
			flag=1;
		}
		if(a[i]==b[i])
		{
			ma[a[i]]++;
		}
		else
		{
	    	ma[a[i]]++;
		    ma[b[i]]++;
	    }
	}
	ll rep=m+1;
	for(i=0;i<m;i++)
	{
		if(ma[a[i]]>1)
		{
		   rep=a[i];
		   f=1;
		   break;
		}
		if(ma[b[i]]>1)
		{
			rep=b[i];
			f=1;
			break;
		}
	}
	cout<<flag<<" "<<f<<endl;
	if(flag==0&&f==0)
	{
		cout<<"OK";
	}
	else
	{
       if(rep>min)
       {
       	  cout<<min<<" 0";
	   }
	   else
	   {
	   	 cout<<rep<<" "<<ma[rep];
	   }
	}
}


#include<bits/stdc++.h>
using namespace std;
#include<string>
typedef long long int ll;
#define fr ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include<algorithm>
#include<vector>
const long long int maxn = 1e3+2;
const long long int mod = 1e3+2;
int main()
{
	fr
	ll n,m;
	cin>>n>>m;
	map<ll,ll> ma;
	ll a[m],b[m],min=n+1,i,flag=0,f=0;
	for(i=0;i<m;i++)
	{
		cin>>a[i];
	    cin>>b[i];
	    if(b[i-1]+1<a[i])
		{
			min=b[i-1]+1;
			flag=1;
		}
		if(a[i]==b[i])
		{
			ma[a[i]]++;
		}
		else
		{
	    	ma[a[i]]++;
		    ma[b[i]]++;
	    }
	}
	ll rep=m+1;
	for(i=0;i<m;i++)
	{
		if(ma[a[i]]>1)
		{
		   rep=a[i];
		   f=1;
		   break;
		}
		if(ma[b[i]]>1)
		{
			rep=b[i];
			f=1;
			break;
		}
	}
	if(flag==0&&f==0)
	{
		cout<<"OK";
	}
	else
	{
       if(rep>min)
       {
       	  cout<<min<<" 0";
	   }
	   else
	   {
	   	 cout<<rep<<" "<<ma[rep];
	   }
	}
}


#include<bits/stdc++.h>
using namespace std;
#include<string>
typedef long long int ll;
#define fr ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include<algorithm>
#include<vector>
const long long int maxn = 1e3+2;
const long long int mod = 1e3+2;
int main()
{
	fr
	ll n,m;
	cin>>n>>m;
	map<ll,ll> ma;
	ll a[m],b[m],min=n+1,i,flag=0,f=0;
	for(i=0;i<m;i++)
	{
		cin>>a[i];
	    cin>>b[i];
	    if(i!=0&&b[i-1]+1<a[i]&&flag==0)
		{
			min=b[i-1]+1;
			flag=1;
		}
		if(a[i]==b[i])
		{
			ma[a[i]]++;
		}
		else
		{
	    	ma[a[i]]++;
		    ma[b[i]]++;
	    }
	}
	if(a[0]!=1)
	{
	cout<<"1 0";
	return 0;
	}
	ll rep=m+1;
	for(i=0;i<m;i++)
	{
		if(ma[a[i]]>1)
		{
		   rep=a[i];
		   f=1;
		   break;
		}
		if(ma[b[i]]>1)
		{
			rep=b[i];
			f=1;
			break;
		}
	}
	if(flag==0&&f==0)
	{
		if(b[m-1]!=n)
		{
			cout<<b[m-1]+1<<" 0";
			return 0;
		}
		cout<<"OK";
	}
	else
	{
       if(rep>min)
       {
       	  cout<<min<<" 0";
	   }
	   else
	   {
	   	 cout<<rep<<" "<<ma[rep];
	   }
	}
}


#include<bits/stdc++.h>
using namespace std;
#include<string>
typedef long long int ll;
#define fr ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include<algorithm>
#include<vector>
const long long int maxn = 1e3+2;
const long long int mod = 1e3+2;
int main()
{
	fr
	ll n,m;
	cin>>n>>m;
	map<ll,ll> ma;
	ll a[m],b[m],min=n+1,i,flag=0,f=0;
	for(i=0;i<m;i++)
	{
		cin>>a[i];
	    cin>>b[i];
	    if(i!=0&&b[i-1]+1<a[i])
		{
			min=b[i-1]+1;
			flag=1;
		}
		if(a[i]==b[i])
		{
			ma[a[i]]++;
		}
		else
		{
	    	ma[a[i]]++;
		    ma[b[i]]++;
	    }
	}
	ll rep=m+1;
	for(i=0;i<m;i++)
	{
		if(ma[a[i]]>1)
		{
		   rep=a[i];
		   f=1;
		   break;
		}
		if(ma[b[i]]>1)
		{
			rep=b[i];
			f=1;
			break;
		}
	}
	if(flag==0&&f==0)
	{
		cout<<"OK";
	}
	else
	{
       if(rep>min)
       {
       	  cout<<min<<" 0";
	   }
	   else
	   {
	   	 cout<<rep<<" "<<ma[rep];
	   }
	}
}


#include<bits/stdc++.h>
using namespace std;
#define fast {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
typedef long long int ll;
typedef string S;
#define M 1e18
#define AS 250002
#define in(x)  cin>>x
#define o(x)  cout<<x
#define sp cout<<' '
#define nw cout<<endl
#define rt return
#define fr(i,a,n) for(ll i=a;i<=n;i++)
#define frm(i,a,n) for(ll i=n;i>=a;i--)
#define P pair<ll,ll>
#define vc vector<ll>
#define pb push_back
#define MP map<ll,ll>
bool sortin(const pair<ll,ll> &e,const pair<ll,ll> &f){return (e.first<f.first);}
ll i,j,k,l,m,n,c,p,q,ts,mn=10e17,mod=10e8+7;
ll a[AS],b[AS],x[AS];
int main()
{
    fast;
    in(n>>m);
    fr(i,1,m)
    {
        in(p>>q);
        a[p]++;a[q+1]--;
    }
    fr(i,1,n)
    {
        a[i]+=a[i-1];
        if(a[i]!=1)
        {
            o(i);sp;o(a[i]);rt 0;
        }
    }
  o("OK");
}


#include<bits/stdc++.h>
using namespace std;
int mp[1000];
int main()
{
    int n,q;
    cin >> n >> q;
    while( q--){
        int x,y;
        cin >> x >> y;
        for(int i=x;i<=y;i++)
        {
            mp[i]++;
        }
    }
    for(int i=1;i<=n;i++){
        if(mp[i]==0){
            cout<<i<<" "<<"0";return 0;
        }
        if(mp[i]>1){
            cout<<i<<" "<<mp[i];return 0;
        }
    }
    cout<<"OK\n";

}


// me & god
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;

const int N = 1e6 + 10;

int n, m;
vector <pair <int, int>> v;

int main() {
//	ios :: sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		v.push_back({a, b});
	}
	sort(v.begin(), v.end());
	if (v[0].first != 1) {
		cout << 1 << " " << 0;
		return 0;
	}
	for (int i = 1; i < m; i++) {
		if (v[i - 1].second < v[i].first - 1) {
			cout << v[i - 1].second + 1 << " " << 0;
			return 0;
		}
		else if (v[i - 1].second > v[i].first - 1) {
			int sum = 0;
			for (auto x: v)
				if (x.first <= v[i].first && x.second >= v[i].first)
					sum++;
			cout << v[i].first << " " << sum;
			return 0;
		}
	}
	if (v[m - 1].second != n) {
		cout << v[m - 1].second + 1 << " " << 0;
		return 0;
	}
	cout << "OK";
	return 0;
}


// me & god
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;

const int N = 1e6 + 10;

int n, m;
vector <pair <int, int>> v;

int main() {
//	ios :: sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		v.push_back({a, b});
	}
	sort(v.begin(), v.end());
	if (v[0].first != 1) {
		cout << 1 << " " << 0;
		return 0;
	}
	for (int i = 1; i < m; i++) {
		if (v[i - 1].second < v[i].first - 1) {
			cout << v[i - 1].second + 1 << " " << 0;
			return 0;
		}
		else if (v[i - 1].second > v[i].first - 1) {
			cout << v[i].first << " " << 2;
			return 0;
		}
	}
	if (v[m - 1].second != n) {
		cout << v[m - 1].second + 1 << " " << 0;
		return 0;
	}
	cout << "OK";
	return 0;
}


#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mp make_pair
#define f first
#define s second
#define pb push_back

const int N = 100 + 5;
const int M = 1e6 + 5;
const int OO = 1e9;
const int mod = 1e9 + 7;

int n,m,a,b,f[N];

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> m;

    while(m--) {

        cin >> a >> b;

        for(int i=a;i<=b;++i) f[i]++;

    }

    for(int i=1;i<=n;++i) {

        if(f[i]!=1) return cout << i << ' ' << f[i] << '\n', 0;

    }

    cout << "OK\n";

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int count[123];
int main() {
    int n,m;
    cin >> n >> m;
    for(int i = 1;i <= m;++i) {
        int a,b;
        cin >> a >> b;
        for(int j = a;j <= b;++j) {
            count[j]++;
        }
    }
    for(int i = 1;i <= n;++i) {
        if(a[i] != 1) {
            cout << i << ' ' << a[i];
            break;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int cnt[123];
int main() {
    int n,m;
    cin >> n >> m;
    for(int i = 1;i <= m;++i) {
        int a,b;
        cin >> a >> b;
        for(int j = a;j <= b;++j) {
            cnt[j]++;
        }
    }
    int OK = true;
    for(int i = 1;i <= n;++i) {
        if(cnt[i] != 1) {
            cout << i << ' ' << cnt[i];
            OK = false;
            break;
        }
    }
    if(OK) cout << "OK";
}


#include<bits/stdc++.h>
using namespace std;
int count[123];
int main() {
    int n,m;
    cin >> n >> m;
    for(int i = 1;i <= m;++i) {
        int a,b;
        cin >> a >> b;
        for(int j = a;j <= b;++j) {
            count[j]++;
        }
    }
    for(int i = 1;i <= n;++i) {
        if(count[i] != 1) {
            cout << i << ' ' << a[i];
            break;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int cnt[123];
int main() {
    int n,m;
    cin >> n >> m;
    for(int i = 1;i <= m;++i) {
        int a,b;
        cin >> a >> b;
        for(int j = a;j <= b;++j) {
            cnt[j]++;
        }
    }
    for(int i = 1;i <= n;++i) {
        if(cnt[i] != 1) {
            cout << i << ' ' << cnt[i];
            break;
        }
    }
}


#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<ll int,ll int>
#define all(a)      (a).begin(),(a).end()
#define fi          first
#define se          second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lb          lower_bound
#define ub          upper_bound
#define bs          binary_search
#define mp          make_pair
#define N           100005
using namespace std;
int main()
{
     int n,m,a,b,i;
     cin>>n>>m;
     int arr[n+1]={0};
     while(m--)
     {
     	cin>>a>>b;
     	for(i=a;i<=b;i++)
     	arr[i]++;
	 }
	 for(i=1;i<=n;i++)
	 {
	 	if(arr[i]==0)
		{
		cout<<i<<" "<<0;
		return 0;
		}
		else if(arr[i]>1)
		{
		cout<<i<<" "<<arr[i];
		return 0;
		}
	 }
	 cout<<"OK";
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int n,m;
	cin >> n >> m;
	int A[100]={0};

	for(int i=0;i<m;i++)
	{
		int a,b;
		cin >> a >> b;

		for(int j=a;j<=b;j++)
		{
			A[j]++;
		}
	}

	for(int i=1;i<=n;i++)
	{
		if(A[i] != 1)
		{
			cout << i << " " << A[i];
			return 0;
		}
	}

	cout << "OK" << endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int n,m;
	cin >> n >> m;
	int A[101]={0};

	for(int i=0;i<m;i++)
	{
		int a,b;
		cin >> a >> b;

		for(int j=a;j<=b;j++)
		{
			A[j]++;
		}
	}

	for(int i=1;i<=n;i++)
	{
		if(A[i] != 1)
		{
			cout << i << " " << A[i];
			return 0;
		}
	}

	cout << "OK" << endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,v[109];
    cin>>n>>m;
    for(int i=1;i<=n;i++)v[i]=0;
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        for(int j=x;j<=y;j++)v[j]++;
    }
    for(int i=1;i<=n;i++){
        if(v[i]!=1){
            cout<<i<<" "<<v[i]<<endl;
            return 0;
        }
    }
    cout<<"OK"<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,v[109],lst;
    cin>>n>>m;
    for(int i=1;i<=n;i++)v[i]=0;
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        lst=y;
        for(int j=x;j<=y;j++)v[j]++;
    }
    for(int i=1;i<=lst;i++){
        if(v[i]!=1){
            cout<<i<<" "<<v[i]<<endl;
            return 0;
        }
    }
    cout<<"OK"<<endl;
    return 0;
}


#include <cstdio>

int main(){

    long n, m; scanf("%ld %ld", &n, &m);
    long cur(0), day(-1), times(1);
    for(long p = 0; p < m; p++){
        long a, b; scanf("%ld %ld", &a, &b);
        if(cur + 1 < a){day = cur + 1; times = 0; break;}
        else if(a < cur + 1){day = a; ++times; if(b > a){break;}}
        cur = b;
    }

    if(day < 0 && cur < n){day = cur + 1; times = 0;}

    if(day < 0){puts("OK");}
    else{printf("%ld %ld\n", day, times);}

    return 0;
}


#include <cstdio>

int main(){

    long n, m; scanf("%ld %ld", &n, &m);
    long cur(0), day(-1), times(0);
    for(long p = 0; p < m; p++){
        long a, b; scanf("%ld %ld", &a, &b);
        if(cur + 1 < a){day = cur + 1; times = 0; break;}
        else if(a < cur + 1){day = a; ++times; if(b > a){break;}}
        cur = b;
    }

    if(day < 0 && cur < n){day = cur + 1; times = 0;}

    if(day < 0){puts("OK");}
    else{printf("%ld %ld\n", day, times);}

    return 0;
}


#include <cstdio>

int main(){

    long n, m; scanf("%ld %ld", &n, &m);
    long cur(0), day(-1), times(-1);
    for(long p = 0; p < m; p++){
        long a, b; scanf("%ld %ld", &a, &b);
        if(cur + 1 < a){day = cur + 1; times = 0; break;}
        else if(a < cur + 1){day = a; times = 2; break;}
        cur = b;
    }

    if(day < 0 && cur < n){day = cur + 1; times = 0;}

    if(day < 0){puts("OK");}
    else{printf("%ld %ld\n", day, times);}

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>

#define pr pair<int,int>
#define prr pair<pr,int>
#define loop(i,n) for(int i=0 ; i<n ; i++)
#define rep(i,x,n) for(int i=x ; i<=n ; i++)
typedef long long ll;

using namespace std;
using namespace __gnu_pbds;

typedef tree<
        ll,
        null_type,
        less<ll>,
        rb_tree_tag,
        tree_order_statistics_node_update>
        ordered_set;

const ll N = 1e2 + 5, MX = 1e7, MN = 0,MOD=1e4+7;
int n,m;
int cnt[N];
pr arr[N];
int main() {
#ifndef ONLINE_JUDGE
    freopen("in.txt", "rt", stdin);
#endif
   // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    scanf("%d %d",&n,&m);
    rep(i,1,m){
        scanf("%d %d",&arr[i].first,&arr[i].second);
        rep(j,arr[i].first,arr[i].second){
            cnt[j]++;
        }
    }
    rep(i,1,n){
        if(cnt[i]!=1){
            printf("%d %d\n",i,cnt[i]);
            return 0;
        }
    }
    printf("OK\n");
    return 0;
}


#include <bits/stdc++.h>

#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define all(s) s.begin(),s.end()
//#define int long long

using namespace std;

const int N = (1e6 + 12);
const int mod = (1e9 + 7);
const int INF = (0x3f3f3f3f);

int cnt[N];
main()
{
	int n, m, l, r;
	cin >> n >> m;
	for(int i = 1;i <= m; i++){
		scanf("%d%d", &l, &r);
		for(int j = l;j <= r; j++){
			cnt[j]++;
		}
	}
	for(int i = 1;i <= n; i++){
		if(cnt[i] != 1){
			cout << i << " " << cnt[i];
			return 0;
		}
	}
	cout << "OK";
}


#include <bits/stdc++.h>

using namespace std;

void fastInOut();

typedef pair<int, int> pii;
typedef long long ll;
const int N = 2e5 + 2;

int arr[101];

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    fastInOut();
    int n, m; cin >> n >> m;
    for(int i=0; i<m; ++i) {
        int a, b; cin >> a >> b;
        for(int j=a; j<=b; ++j)
            arr[j]++;
    }
    for(int i=1; i<=n; ++i) {
        if(arr[i] != 1) {
            cout << i << ' ' << arr[i] << '\n';
            return 0;
        }
    }
    cout << "OK\n";
    return 0;
}

void fastInOut() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
  int n,k;
  cin >> n >> k;
  map<int,int> mp;
  while(k--)
  {
      int a,b;
      cin >> a >> b;
      mp[a]++;

      mp[b+1]--;
  }

  for(int i=1; i<=n; i++)mp[i]+=0;
   int sum = 0;

  for(auto &i : mp)
  {
      sum += i.second ;
      i.second = sum ;
  }

 for(int i=1; i<=n; i++)
 {
     if(mp[i]==0 || mp[i]>1)
     {
         cout << i  << " " << mp[i] << endl;
         return 0;
     }
 }

cout << "OK" << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define nl cout << '\n'
#define precision(a) cout << fixed << setprecision(a)
#define SIZE(a) (a).size()
#define reset(a, b) memset(a, (b), sizeof(a))
#define FOR(i, a, b, inc) for (ll i = a; i <= b; i += inc)
#define rfor(i, a, b, inc) for (ll i = a; i >= b; i -= inc)
#define forn(i, a, b) FOR(i, a, b, 1)
#define rforn(i, a, b) rfor(i, a, b, 1)
#define rep(i, a, b) FOR(i, a, b - 1, 1)
#define rrep(i, a, b) rfor(i, a - 1, b, 1)
#define All(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define SORT(a) sort(All(a))
#define rsort(a) sort(rall(a))
#define count1(a) __builtin_popcount(a)
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define FASTIO               \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
const double pi = acos(-1.0);
typedef long long int ll;
typedef unsigned long long int ul;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pll> vll;
typedef unsigned buf_t;

template <class T>
inline void read(T &x)
{
    char c;
    int flag = 1;
    while ((c = getchar()) < '0' || c > '9')
        if (c == '-')
            flag *= -1;
    x = c - '0';
    while ((c = getchar()) >= '0' && c <= '9')
        x = x * 10 + c - '0';
    x *= flag;
    return;
}

int main()
{
    //  g++ file.cpp -o file -std=c++11
    //	freopen("input.txt","r",stdin);
    //	freopen("output.txt","w",stdout);
    FASTIO; /// enter here
    ll n, m;
    map<ll, ll> ct;
    cin >> n >> m;
    ll a[m + 5], b[m + 5];
    forn(i, 1, m)
    {
        cin >> a[i] >> b[i];
        forn(j, a[i], b[i])
        {
            ct[j] += 1;
        }
    }
    forn(i, 1, n)
    {
        if (ct[i] == 0 || ct[i] > 1)
        {
            cout << i << ' ' << ct[i] << endl;
            return 0;
        }
    }
    cout << "OK" << endl;

    return 0;
}


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

int main()
{
	long long int i,j,k,l,m,n,a,b;
	cin>>n>>m;
	map<long long int,long long int>mp;
	while(m--)
	{
		cin>>a>>b;
		for(i=a;i<=b;i++)
		{
			mp[i]++;
		}
	}
	for(i=1;i<=n;i++)
	{
		if(mp[i]!=1)
		{
			cout<<i<<" "<<mp[i];
			return 0;
		}
	}
	cout<<"OK";
}


#include <bits/stdc++.h>

using namespace std;

int cou[105];

int main () {
  memset(cou, 0, sizeof(int)*105);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    for (int j = a; j <= b; j++)
      cou[j]++;
  }
  for (int i = 1; i <= n; i++) {
    if (cou[i] != 1) {
      cout << i << " " << cou[i] << "\n";
      return 0;
    }
  }
  cout << "OK" <<x endl;
}


#include <bits/stdc++.h>

using namespace std;

int cou[105];

int main () {
  // memset(cou, 0, sizeof(int)*105);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i < m; i++) {
    int a, b;
    cin >> a >> b;
    for (int j = a; j <= b; j++)
      cou[j]++;
  }
  for (int i = 1; i < m; i++) {
    if (cou[i] != 1) {
      cout << i << " " << cou[i] << "\n";
      return 0;
    }
  }
  cout << "OK" << endl;
}


#include <bits/stdc++.h>

using namespace std;

int cou[105];

int main () {
  memset(cou, 0, sizeof(int)*105);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    for (int j = a; j <= b; j++)
      cou[j]++;
  }
  for (int i = 1; i <= n; i++) {
    if (cou[i] != 1) {
      cout << i << " " << cou[i] << "\n";
      return 0;
    }
  }
  cout << "OK" << endl;
}


#include <bits/stdc++.h>

using namespace std;

int cou[101];

int main () {
  memset(cou, 0, 101);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    for (int j = a; j <= b; j++)
      cou[j]++;
  }
  for (int i = 1; i < m; i++) {
    if (cou[i] != 1) {
      cout << i << " " << cou[i] << "\n";
      return 0;
    }
  }
  cout << "OK" << endl;
}


#include <unordered_map>
#include <functional>
#include <algorithm>
#include <iterator>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <fstream>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <cstddef>
#include <vector>
#include <bitset>
#include <cstdio>
#include <limits>
#include <cctype>
#include <deque>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <regex>
#include <list>
#include <map>
#include <set>

using namespace std;

#define mp make_pair
#define pb push_back
#define mref mem_fun_ref
#define bis back_inserter
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for(int i = 0; i < int64(n); ++i)
#define forni(i, n, l) for(int i = int64(l); i < int(n); ++i)
typedef long long int int64;
typedef pair<int64, int64> pint;
typedef vector<int64> vint;
const int64 Inf = 1e18 + 12;
typedef vector<vector<bool> > matrix;
template <typename T> void alert(const T& t) { cout << t << endl; exit(0); }
const int64 MOD = 1e9+7;
const int64 N = 1e5 + 20;
const double pi = 3.1415926535897932384626433832795028841971;

int main()
{
#ifdef _DEBUG
	freopen("in.txt", "r", stdin);
	//	freopen("out.txt", "w", stdout);
#else
	{
		//freopen("glasses.in", "r", stdin);
		//freopen("glasses.out", "w", stdout);
		ios::sync_with_stdio(false);
		cin.tie(0);
		cout.tie(0);
	}
#endif

	int n, m; cin >> n >> m;
	vector<int> goToHell(n, 0);
	forn(i, m)
	{
		int a, b; cin >> a >> b;
		a--; b--;
		for (int j = a; j <= b; ++j)
			goToHell[j]++;
	}
	forn(i, n)
	{
		if (goToHell[i] != 1)
		{
			cout << i + 1 << " " << goToHell[i] << endl;
			return 0;
		}
	}
	alert("OK");
	return 0;
}


#include <unordered_map>
#include <functional>
#include <algorithm>
#include <iterator>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <fstream>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <cstddef>
#include <vector>
#include <bitset>
#include <cstdio>
#include <limits>
#include <cctype>
#include <deque>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <regex>
#include <list>
#include <map>
#include <set>

using namespace std;

#define mp make_pair
#define pb push_back
#define mref mem_fun_ref
#define bis back_inserter
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for(int i = 0; i < int64(n); ++i)
#define forni(i, n, l) for(int i = int64(l); i < int(n); ++i)
typedef long long int int64;
typedef pair<int64, int64> pint;
typedef vector<int64> vint;
const int64 Inf = 1e18 + 12;
typedef vector<vector<bool> > matrix;
template <typename T> void alert(const T& t) { cout << t << endl; exit(0); }
const int64 MOD = 1e9+7;
const int64 N = 1e5 + 20;
const double pi = 3.1415926535897932384626433832795028841971;

int main()
{
#ifdef _DEBUG
	freopen("in.txt", "r", stdin);
	//	freopen("out.txt", "w", stdout);
#else
	{
		//freopen("glasses.in", "r", stdin);
		//freopen("glasses.out", "w", stdout);
		ios::sync_with_stdio(false);
		cin.tie(0);
		cout.tie(0);
	}
#endif

	int n, m; cin >> n >> m;
	pair<int, int> res(0, 1);
	int last = 0;
	forn(i, m)
	{
		int a, b;
		cin >> a >> b;
		if (a <= last || a > last + 1)
		{
			if (a <= last)
			{
				if (res.first == last) res.second++;
				else if (res.first == 0)
				{
					res.second++;
					res.first = last;
				}
				else
				{
					cout << res.first << " " << res.second << endl;
					return 0;
				}
			}
			else
			{
				if (res.first == 0)
					cout << last + 1 << " 0 " << endl;
				else cout << res.first << " " << res.second << endl;
				return 0;
			}
		}
		last = b;
	}
	cout << "OK" << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define ff first
#define ss second
#define pb 1push_back
#define mp make_pair
#define mod 1000000009
#define all(x) x.begin(),x.end()
#define db1(x) cout<<#x<<" "<<x<<endl
#define db2(x,y) cout<<#x"="<<x<<" "<<#y"="<<y<<endl
#define v2d(v,x,y) vector<vector<int>>v(x,vector<int>(y))
void sublime();

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // cout<<setprecision(9)<<fixed;
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int tc=1,t=1;
    // cin>>tc;
    while(tc--){
        // cout<<"Case #"<<t++<<": ";
        sublime();
        cout<<endl;
    }
    // cerr<<"Time= "<<(double)clock()/CLOCKS_PER_SEC<<endl;
}

void sublime()
{
    int i,a,b,n,m;
    cin>>n>>m;
    vector<int> day(n+2);//0 for iterative adding without precondition, and m+1 for adding at another index
    for(i=1;i<=m;i++){
        cin>>a>>b;
        day[a]++;
        day[b+1]--;
    }
    for(i=1;i<=m;i++){
        day[i]+=day[i-1];
        if(day[i]!=1){
            cout<<i<<' '<<day[i];
            return;
        }
    }
    cout<<"OK";
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define ff first
#define ss second
#define pb 1push_back
#define mp make_pair
#define mod 1000000009
#define all(x) x.begin(),x.end()
#define db1(x) cout<<#x<<" "<<x<<endl
#define db2(x,y) cout<<#x"="<<x<<" "<<#y"="<<y<<endl
#define v2d(v,x,y) vector<vector<int>>v(x,vector<int>(y))
void sublime();

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // cout<<setprecision(9)<<fixed;
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int tc=1,t=1;
    // cin>>tc;
    while(tc--){
        // cout<<"Case #"<<t++<<": ";
        sublime();
        cout<<endl;
    }
    // cerr<<"Time= "<<(double)clock()/CLOCKS_PER_SEC<<endl;
}

void sublime()
{
    int i,a,b,n,m;
    cin>>n>>m;
    vector<int> day(n+3);
    for(i=1;i<=m;i++){
        cin>>a>>b;
        day[a]++;
        day[b+1]--;
    }
    for(i=1;i<=n;i++){
        day[i]+=day[i-1];
        if(day[i]!=1){
            cout<<i<<' '<<day[i];
            return;
        }
    }
    // for(i=1;i<=n;i++) cout<<day[i]<<" ";
    cout<<"OK";
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define ff first
#define ss second
#define pb 1push_back
#define mp make_pair
#define mod 1000000009
#define all(x) x.begin(),x.end()
#define db1(x) cout<<#x<<" "<<x<<endl
#define db2(x,y) cout<<#x"="<<x<<" "<<#y"="<<y<<endl
#define v2d(v,x,y) vector<vector<int>>v(x,vector<int>(y))
void sublime();

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // cout<<setprecision(9)<<fixed;
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int tc=1,t=1;
    // cin>>tc;
    while(tc--){
        // cout<<"Case #"<<t++<<": ";
        sublime();
        cout<<endl;
    }
    // cerr<<"Time= "<<(double)clock()/CLOCKS_PER_SEC<<endl;
}

void sublime()
{
    int i,a,b,n,m;
    cin>>n>>m;
    vector<int> day(m+2);//0 for iterative adding without precondition, and m+1 for adding at another index
    for(i=1;i<=m;i++){
        cin>>a>>b;
        day[a]++;
        day[b+1]--;
    }
    for(i=1;i<=m;i++){
        day[i]+=day[i-1];
        if(day[i]!=1){
            cout<<i<<' '<<day[i];
            return;
        }
    }
    cout<<"OK";
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define ff first
#define ss second
#define pb 1push_back
#define mp make_pair
#define mod 1000000009
#define all(x) x.begin(),x.end()
#define db1(x) cout<<#x<<" "<<x<<endl
#define db2(x,y) cout<<#x"="<<x<<" "<<#y"="<<y<<endl
#define v2d(v,x,y) vector<vector<int>>v(x,vector<int>(y))
void sublime();

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // cout<<setprecision(9)<<fixed;
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int tc=1,t=1;
    // cin>>tc;
    while(tc--){
        // cout<<"Case #"<<t++<<": ";
        sublime();
        cout<<endl;
    }
    // cerr<<"Time= "<<(double)clock()/CLOCKS_PER_SEC<<endl;
}

void sublime()
{
    int i,a,b,n,m;
    cin>>n>>m;
    vector<int> day(n+3);
    for(i=1;i<=m;i++){
        cin>>a>>b;
        day[a]++;
        day[b+1]--;
    }
    for(i=1;i<=n;i++){
        day[i]+=day[i-1];
        if(day[i]!=1){
            cout<<i<<' '<<day[i];
            return;
        }
    }
    for(i=1;i<=n;i++) cout<<day[i]<<" ";
    cout<<"OK";
}


#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <array>
#include <list>

struct TQuery {
    size_t l, r;
};

int main() {
#define LOCAL 0
#if LOCAL
    std::ifstream ifs("input.txt");
#define ids ifs
#else
#define ids std::cin
#endif

    size_t n = 0, m = 0;
    ids >> n >> m;
    std::vector<TQuery> queries(m);
    for (size_t i = 0; i < m; ++i)
        ids >> queries[i].l >> queries[i].r;

    size_t e = 1, c = 0;

    bool err = false;
    for (const auto & q : queries) {
        if (e == q.l)
            e = q.r + 1;
        else {
            err = true;
            break;
        }
    }
    for (const auto & q : queries) {
        if (q.l <= e && e <= q.r) {
            ++c;
        }
    }

    if (err) {
        std::cout << e << " " << c;
    }
    else
        std::cout << "OK";
    return 0;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <array>
#include <list>

struct TQuery {
    size_t l, r;
};

int main() {
#define LOCAL 0
#if LOCAL
    std::ifstream ifs("input.txt");
#define ids ifs
#else
#define ids std::cin
#endif

    size_t n = 0, m = 0;
    ids >> n >> m;
    std::vector<TQuery> queries(m);
    for (size_t i = 0; i < m; ++i)
        ids >> queries[i].l >> queries[i].r;

    size_t e = 1, c = 0;

    bool err = false;
    for (const auto & q : queries) {
        if (e == q.l)
            e = q.r + 1;
        else {
            e = std::min(e, q.l);
            err = true;
            break;
        }
    }
    for (const auto & q : queries) {
        if (q.l <= e && e <= q.r) {
            ++c;
        }
    }

    if (err || e != n + 1) {
        std::cout << e << " " << c;
    }
    else
        std::cout << "OK";
    return 0;
}


#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <array>
#include <list>

struct TQuery {
    size_t l, r;
};

int main() {
#define LOCAL 0
#if LOCAL
    std::ifstream ifs("input.txt");
#define ids ifs
#else
#define ids std::cin
#endif

    size_t n = 0, m = 0;
    ids >> n >> m;
    std::vector<TQuery> queries(m);
    for (size_t i = 0; i < m; ++i)
        ids >> queries[i].l >> queries[i].r;

    size_t e = 1, c = 0;

    bool err = false;
    for (const auto & q : queries) {
        if (e == q.l)
            e = q.r + 1;
        else {
            e = std::min(e, q.l);
            err = true;
            break;
        }
    }
    for (const auto & q : queries) {
        if (q.l <= e && e <= q.r) {
            ++c;
        }
    }

    if (err) {
        std::cout << e << " " << c;
    }
    else
        std::cout << "OK";
    return 0;
}


#include<bits/stdc++.h>
#define mx 100000
#define pb push_back
#define siz(v) v.size()
typedef unsigned long long ull;
typedef long long  ll;
using namespace std;

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

	int day,n;
	cin>>day>>n;
	int arr[day+5]={0};

	while(n--)
	{
		int a,b;
		cin>>a>>b;
		for(int i=a;i<=b;++i)
			arr[i]++;
	}

	bool f=false;
	for(int i=1;i<=day;++i){
		if (arr[i]>1 || arr[i]==0){
			cout<<i<<" "<<arr[i]<<"\n";
			f=true;
			break;
		}
	}
	if (!f)
		cout<<"OK\n";

 return 0;
 }


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define ve vector
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
int main()
{
	ll n,m;
	cin>>n>>m;
	ve<ll> a(m,0);
	ve<ll> b(m,0);
	ll ans=0;
	ll day=0;
	for(ll i=0;i<m;i++)
	{
		cin>>a[i]>>b[i];
	}
	if(a[0]!=1)
		cout<<1<<" "<<0;
	else
	{
		ll i=0;
		for(i=1;i<m&&a[i]==(b[i-1]+1);i++)
		{

		}
		if(i!=m)
		{
			if(a[i]==b[i-1])
			{
				ans=2;
				cout<<a[i]<<" ";
				while(i<m-1&&a[i]==b[i]&&a[i+1]==b[i])
				{
					i++;
					ans=ans+1;
				}
				cout<<ans;
			}
			else if(a[i]>b[i-1]+1)
			{
				cout<<b[i-1]+1<<" "<<0;
			}

		}
		else
		{
			if(b[m-1]==n)
				cout<<"OK";
			else
				cout<<b[m-1]+1<<" "<<0;
		}

	}

}


#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	ll i,j,k,l,n,m;
	cin>>n>>m;

	ll fl[n+1]={0};
	for(i=1;i<=m;i++){
		cin>>k>>l;
		for(j=k;j<=l;j++){
			fl[j]++;
		}
	}

	ll an=-1,v;
	for(i=1;i<=n;i++){
		if(fl[i]!=1){
			an=i; v=fl[i];
			break;
		}
	}
	if(an==-1){
		cout<<"OK"<<endl;
	}
	else cout<<an<<" "<<v<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	ll i,j,k,l,n,m;
	cin>>n>>m;

	ll a=0,b=0; ll flg=0,an=0,v=0;
	for(i=1;i<=m;i++){
		cin>>k>>l;
		if(k==b+1){
			a=k; b=l;
		}
		else{
			//cout<<i<<endl;
			if(k==b){
				v=k;
				an=2;
			}
			else{
				v=b+1;
				an=0;
			}
			break;
		}
	}
	if(i==m+1){
		cout<<"OK"<<endl;
	}
	else cout<<v<<" "<<an<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	ll i,j,k,l,n,m;
	cin>>n>>m;

	ll fl[n+1]={0};
	for(i=1;i<=m;i++){
		cin>>k>>l;
		for(j=k;j<=l;j++){
			fl[j]++;
		}
	}

	ll an=-1,v;
	for(i=1;i<=n;i++){
		if(fl[i]!=1){
			an=i; v=fl[i];
		}
	}
	if(an==-1){
		cout<<"OK"<<endl;
	}
	else cout<<an<<" "<<v<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
main() {
    int n,m;
    cin>>n>>m;
    int A[n];
    memset(A,0,sizeof(A));
    while (m--) {
        int a,b;
        cin>>a>>b;
        a--; b--;
        A[a]++;
        if (b+1<n) A[b+1]--;
    }
    for (int i=1; i<n; i++) A[i]+=A[i-1];
    for (int i=0; i<n; i++) {
        if (!A[i] || A[i]>1) {
            cout<<i+1<<' '<<A[i];
            return 0;
        }
    }
    cout<<"OK";
    return 0;
}


#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define ll long long
#define ld long double
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define pie 3.14159265358979323846264338327950L
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define umap unordered_map<int, int>
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define endl "\n"
#define int long long
#define fi first
#define se second
#define sz(x) (int)x.size()

#define trace1(x)                cout << #x << ": " << x << endl;
#define trace2(x, y)             cout << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cout << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

using namespace std;

int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
int gcd(int a,int b){ if(!a)return b;return gcd(b%a,a);}
int lcm(int a, int b) { return (a*b)/ gcd(a,b);}

const int template_array_size = 1e6 + 2047;
const int N = 1e5 + 6;
const int mod = 1e9 + 7;

int mul(int a, int b) {
    return ( a % mod ) * (b %  mod) % mod;
}

int add(int a, int b) {
    return (a+b) % mod;
}

int sub(int a, int b) {
    return (a%mod - b%mod + mod) % mod;
}

int divide(int a, int b) {
    return  a * (int)pow(b,mod-2) % mod;
}

int dp[10009];

void test_case() {
    int n,m;
    cin>>n>>m;

    for(int  i=0; i<m; i++) {
        int x, y;
        cin>>x>>y;

        dp[x]++;
        dp[y+1]--;
    }

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

    for(int i=1; i<=n; i++) {
        if(dp[i] != 1) {
            cout<<i<<" "<<dp[i]<<endl;
            return;
        }
    }

    cout<<"OK"<<endl;
}

int32_t main ()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(20);

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int t = 1;
    // cin >> t;
    while (t--)
    {
        test_case();
    }
}


#include <bits/stdc++.h>

#define x0 abc
#define y0 ABC
#define x1 abcd
#define y1 ABCD
#define xn abcde
#define yn ABCDE

#define fi first
#define se second
#define m_p make_pair

#define p_b push_back
#define po_b pop_back

#define endl '\n'

#define OUT cout << "-------" << endl;

using namespace std;

int l[181], r[181], n, i, k;

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

    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> k;

    for (i = 1; i <= k; i++) cin >> l[i] >> r[i];

    l[k + 1] = n + 1;

    for (i = 0; i <= k; i++)
        if (l[i + 1] - r[i] != 1) {
            if (l[i + 1] - r[i] == 0)
            cout << r[i] << " 2";
            else cout << r[i] + 1 << " 0";

            cout << endl;

            return 0;
        }

    cout << "OK" << endl;

    return 0;
}


#include <bits/stdc++.h>

#define x0 abc
#define y0 ABC
#define x1 abcd
#define y1 ABCD
#define xn abcde
#define yn ABCDE

#define fi first
#define se second
#define m_p make_pair

#define p_b push_back
#define po_b pop_back

#define endl '\n'

#define OUT cout << "-------" << endl;

using namespace std;

int l[181], r[181], n, i, k, kol, nom;

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

    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> k;

    for (i = 1; i <= k; i++) cin >> l[i] >> r[i];

    l[k + 1] = n + 1;

    for (i = 0; i <= k; i++)
        if (l[i + 1] - r[i] != 1) {
            if (l[i + 1] - r[i] == 0) {
                cout << r[i] << " ";

                nom = r[i];

                for (i = 1; i <= k; i++)
                    if ((l[i] <= nom) && (nom <= r[i])) kol++;

                cout << kol;
            }
            else cout << r[i] + 1 << " 0";

            cout << endl;

            return 0;
        }

    cout << "OK" << endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define out(x) cout<<x<<endl
#define in(x) cin>>x
#define iin(x,y) cin>>x>>y
#define outt(x,y) cout<<x<<y<<endl
#define outs(x,y) cout<<x<<" "<<y<<endl

int main()
{
    ll n,m,p,q,c,i,j,sum=0,cnt=0,ans,res;
    iin(n,m);
    ll a[n+10];
    for(i=1;i<=m*2;i+=2)
    {
        a[i]=0;
        a[i+1]=0;
        iin(p,q);
        for(j=p;j<=q;j++)a[j]++;
    }
    for(i=1;i<n;i++)
    {
        if(a[i]!=1)
        {
            cout<<i<<" "<<a[i]<<endl;
            return 0;
        }
    }
    out("OK");

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define out(x) cout<<x<<endl
#define in(x) cin>>x
#define iin(x,y) cin>>x>>y
#define outt(x,y) cout<<x<<y<<endl
#define outs(x,y) cout<<x<<" "<<y<<endl

int main()
{
    ll n,m,p,q,c,i,j,sum=0,cnt=0,ans,res;
    iin(n,m);
    vector<ll>a(105,0);
    for(i=1; i<=m*2; i+=2)
    {
        iin(p,q);
        for(j=p; j<=q; j++)
            a[j]++;
    }
    for(i=1; i<=n; i++)
    {
        if(a[i]!=1)
        {
            cout<<i<<" "<<a[i]<<endl;
            return 0;
        }
    }
    out("OK");

    return 0;
}


// This code writed by chtholly_micromaker(MicroMaker)
#include <bits/stdc++.h>
#define reg register
using namespace std;
const int MaxN=151;
template <class t> inline void read(t &s)
{
	s=0;
	reg int f=1;
	reg char c=getchar();
	while(!isdigit(c))
	{
		if(c=='-')
			f=-1;
		c=getchar();
	}
	while(isdigit(c))
		s=(s<<3)+(s<<1)+(c^48),c=getchar();
	s*=f;
	return;
}
int flower[MaxN];
signed main(void)
{
	int n,m;
	cin>>n>>m;
	reg int l,r;
	for(int i=1;i<=m;++i)
	{
		cin>>l>>r;
		for(int j=l;j<=r;++j)
			++flower[j];
	}
	for(int i=1;i<=n;++i)
		if(flower[i]!=1)
		{
			printf("%d %d\n",i,flower[i]);
			return 0;
		}
	puts("OK");
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <fstream>
#define ll long long ;

using namespace std ;

inline int read()
{
	int X=0; bool flag=1; char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') flag=0; ch=getchar();}
	while(ch>='0'&&ch<='9') {X=(X<<1)+(X<<3)+ch-'0'; ch=getchar();}
	if(flag) return X;
	return ~(X-1);
}

int main() {
    int n , m , x , y ;
    n = read() ;
    m = read() ;
    vector<int> day(n + 5 , 0) ;
    for(int i = 0 ; i < m ; ++ i){
        x = read() ;
        y = read() ;
        day[x - 1] ++ ;
        day[y] -- ;
    }
    for(int i = 1 ; i < n ; ++ i)
        day[i] += day[i - 1] ;
    for(int i = 0 ; i < n ; ++ i)
        if(day[i] != 1){
            cout << i + 1 << " " << day[i] ;
            return 0 ;
        }
    cout << "OK" ;
    return 0;
}


///        Saniuzzaman Robin           ///
///        CSE'08, Comilla University  ///

#include<bits/stdc++.h>

/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
*/

using namespace std;

/*--------------------------Containers------------------------*/
typedef     long long int           ll;
typedef     unsigned long long int  ull;
typedef     vector < int >          vi;
typedef     vector < ll >           vll;
typedef     vector < vi >           vvi;
typedef     pair< int,int >         pi;
typedef     pair< ll, ll >          pll;
typedef     vector< pi >            vpi;
typedef     vector< pll >           vpll;
/*------------------------------------------------------------*/

/*--------------------------Limits & Constants----------------*/
#define     MAX                 200007
#define     MOD                 int(1e9+7)
#define     INF                 ll(8230219982008199610)
#define     MINF                ll(-8230219982008199610)
#define     IL                  INT_MAX
#define     MIL                 INT_MIN
#define     PI                  2*acos(0.0)
/*------------------------------------------------------------*/

/*--------------------------Macros----------------------------*/
#define     fast                ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define     pf                  printf
#define     sc                  scanf
#define     all(a)              (a).begin(),(a).end()
#define     sz(x)               int(x.size())
#define     pb                  push_back
#define     eb                  emplace_back
#define     mp                  make_pair
#define     ff                  first
#define     ss                  second
#define     mem(a,n)            memset(a, n, sizeof(a) )
#define     gcd(a,b)            __gcd(a,b)
#define     lcm(a,b)            (a*(b/gcd(a,b)))
#define     unik(v)             v.resize(distance(v.begin(),unique(all(v))))
/*------------------------------------------------------------*/

/*----------------------Scans and Prints----------------------*/

#define     print(a,n)          for(int pr = 0; pr<int(n); pr++)cout<<a[pr]<<" ";cout<<endl
#define     printa(x)           cout<<x<<endl;
#define     debug               cout<<" OK "<<endl
#define     t_case(t)           for(int cs=1; cs<=t; cs++)
/*------------------------------------------------------------*/

/*------------------------Graph Moves-------------------------*/
//const int dx[]= {+1,-1,+0,+0};
//const int dy[]= {+0,+0,+1,-1};
//const int dx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int dy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int dx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int dy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------------------*/

/*------------------------Bitmask-----------------------------*/
//int Set(int N,int pos){return N = (N (1<<pos));}
//int reset(int N,int pos){return N = (N & ~(1<<pos));}
//bool check(int N,int pos){return (bool)(N & (1<<pos));}
/*------------------------------------------------------------*/

///void Sieve(int n){bool prime[n+1];memset(prime,true,sizeof(prime));for(int p=2; p*p<=n; p++){if(prime[p]==true){for(int i=p*p; i<=n;i+= p)prime[i] = false;}}}
///ll POW(ll a, ll b){ll res = 1;while (b > 0){if (b & 1)res = res * a;a = a * a;b >>= 1;}return res;}
///ll bigmod(ll a, ll b, ll m){a%=m;ll res=1;while(b>0){if(b&1)res=res*a%m;a=a*a%m;b>>=1;}return res;}
///ll INV(ll a,ll m){return bigmod(a,m-2,m);}
///int phi[500007];void phi(int N){for(int i=2; i<=N; i++)phi[i] = i;for(int i =2; i<=N; i++){if(phi[i]==i){for(int j=i; j<=N; j+=i)phi[j]-=phi[j]/i;}}}

int main()
{
    fast;
    int n, m;
    cin>>n>>m;
    vector < pi > v;
    int a, b, water[n+7] = {0};
    for(int i=0; i<m; i++)
    {
        cin>>a>>b;
        for(int j=a; j<=b; j++)
            water[j]++;
        v.pb(mp(a,b));
    }
    int pos = 0;
    for(int i=0; i<v.size(); i++)
    {
        if(v[i].ff==pos+1)
        {
            pos = v[i].ss;
        }
        else
        {
            cout<<min(pos+1,v[i].ff)<<" "<<water[min(pos+1,v[i].ff)]<<endl;
            return 0;
        }
    }
    if(pos<n)
        cout<<pos+1<<" "<<0<<endl;
    else
        cout<<"OK"<<endl;
    return 0;
}


///        Saniuzzaman Robin           ///
///        CSE'08, Comilla University  ///

#include<bits/stdc++.h>

/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
*/

using namespace std;

/*--------------------------Containers------------------------*/
typedef     long long int           ll;
typedef     unsigned long long int  ull;
typedef     vector < int >          vi;
typedef     vector < ll >           vll;
typedef     vector < vi >           vvi;
typedef     pair< int,int >         pi;
typedef     pair< ll, ll >          pll;
typedef     vector< pi >            vpi;
typedef     vector< pll >           vpll;
/*------------------------------------------------------------*/

/*--------------------------Limits & Constants----------------*/
#define     MAX                 200007
#define     MOD                 int(1e9+7)
#define     INF                 ll(8230219982008199610)
#define     MINF                ll(-8230219982008199610)
#define     IL                  INT_MAX
#define     MIL                 INT_MIN
#define     PI                  2*acos(0.0)
/*------------------------------------------------------------*/

/*--------------------------Macros----------------------------*/
#define     fast                ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define     pf                  printf
#define     sc                  scanf
#define     all(a)              (a).begin(),(a).end()
#define     sz(x)               int(x.size())
#define     pb                  push_back
#define     eb                  emplace_back
#define     mp                  make_pair
#define     ff                  first
#define     ss                  second
#define     mem(a,n)            memset(a, n, sizeof(a) )
#define     gcd(a,b)            __gcd(a,b)
#define     lcm(a,b)            (a*(b/gcd(a,b)))
#define     unik(v)             v.resize(distance(v.begin(),unique(all(v))))
/*------------------------------------------------------------*/

/*----------------------Scans and Prints----------------------*/

#define     print(a,n)          for(int pr = 0; pr<int(n); pr++)cout<<a[pr]<<" ";cout<<endl
#define     printa(x)           cout<<x<<endl;
#define     debug               cout<<" OK "<<endl
#define     t_case(t)           for(int cs=1; cs<=t; cs++)
/*------------------------------------------------------------*/

/*------------------------Graph Moves-------------------------*/
//const int dx[]= {+1,-1,+0,+0};
//const int dy[]= {+0,+0,+1,-1};
//const int dx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int dy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int dx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int dy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------------------*/

/*------------------------Bitmask-----------------------------*/
//int Set(int N,int pos){return N = (N (1<<pos));}
//int reset(int N,int pos){return N = (N & ~(1<<pos));}
//bool check(int N,int pos){return (bool)(N & (1<<pos));}
/*------------------------------------------------------------*/

///void Sieve(int n){bool prime[n+1];memset(prime,true,sizeof(prime));for(int p=2; p*p<=n; p++){if(prime[p]==true){for(int i=p*p; i<=n;i+= p)prime[i] = false;}}}
///ll POW(ll a, ll b){ll res = 1;while (b > 0){if (b & 1)res = res * a;a = a * a;b >>= 1;}return res;}
///ll bigmod(ll a, ll b, ll m){a%=m;ll res=1;while(b>0){if(b&1)res=res*a%m;a=a*a%m;b>>=1;}return res;}
///ll INV(ll a,ll m){return bigmod(a,m-2,m);}
///int phi[500007];void phi(int N){for(int i=2; i<=N; i++)phi[i] = i;for(int i =2; i<=N; i++){if(phi[i]==i){for(int j=i; j<=N; j+=i)phi[j]-=phi[j]/i;}}}

int main()
{
    fast;
    int n, m;
    cin>>n>>m;
    vector < pi > v;
    int a, b, water[n+7] = {0};
    for(int i=0; i<m; i++)
    {
        cin>>a>>b;
        for(int j=a; j<=b; j++)
            water[j]++;
        v.pb(mp(a,b));
    }
    int pos = 0;
    for(int i=0; i<v.size(); i++)
    {
        if(v[i].ff==pos+1)
        {
            pos = v[i].ss;
        }
        else
        {
            cout<<min(pos+1,v[i].ff)<<" "<<water[min(pos+1,v[i].ff)]<<endl;
            return 0;
        }
    }
    cout<<"OK"<<endl;
    return 0;
}


/*
ID: Sho10
LANG: C++
*/
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,m;
pair<ll,ll>a[100005];
map<ll,ll>viz;
int32_t main(){
CODE_START;
cin>>n>>m;
for(ll i=0;i<m;i++)
{
    cin>>a[i].f>>a[i].s;
    for(ll j=a[i].f;j<=a[i].s;j++)
        viz[j]++;
}
for(ll i=1;i<=n;i++)
{
    if(viz[i]!=1){
        cout<<i<<' '<<viz[i]<<endl;
        return 0;
    }
}
cout<<"OK"<<endl;
}


#include <bits/stdc++.h>

using namespace std;

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

ios_base::sync_with_stdio(false);
    cin.tie(NULL);

int n,d;
cin>>n>>d;
int arr[n+1]={0};
for (int i = 0; i < d; i++)
{
int a,b;
cin>>a>>b;
for (int i = a; i <=b; i++)
{arr[i]++;
// 	for (int i = 0; i < n; ++i)
// {cout<<arr[i];
// 	/* code */
// }cout<<endl;

}

}

bool flag=true;
	// for (int i = 0; i < n; ++i)
	// {cout<<arr[i];
	// 	/* code */
	// }cout<<endl;
for (int i = 1; i <= n; i++)
{if (arr[i]!=1){cout<<i<<" "<<arr[i];flag=false;break;
}

}
if (flag){cout<<"OK";}

return 0;}


#include<bits/stdc++.h>
using namespace std;
int main()
{
 int n, k, flag=0,x, y, i, j;
 cin>>n>>k;
 multimap<int,int>a;
 vector<int>b(n+1,0);
 for(i=0;i<k;i++)
 {
 	cin>>x>>y;
 	a.insert(make_pair(x,y));
 }
 for(auto e:a)
 {
 	for(j=e.first;j<=e.second;j++)
 	b[j]+=1;
 }
 for(i=1;i<=n;i++)
 {
 	if(b[i]!=1)
 	{
 		flag=1;
 		break;
 	}
 }
 if(flag==1)
 cout<<i<<" "<<b[i]<<endl;
 else
 cout<<"OK"<<endl;
 return 0;
}


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

int n,m;
int a[123],b[123];
int c[12300];
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i]>>b[i];
        while(a[i]<=b[i]){
           c[a[i]]++;
           a[i]++;
        }
    }

    // if(checK()){
        // cout<<"OK"<<endl;
    // }
    for(int i=1;i<=n;i++)
    {
        if(c[i]!=1)
        {
            cout<<i<<" "<<c[i]<<endl;
            exit(0);
        }
    }
    cout<<"OK"<<endl;
    return 0;
}