stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

#define int long long

#define pb push_back

#define faster ios::sync_with_stdio(0)

const int N  = 509;

vector<int>v[N+5];



int32_t main()

{

    faster;

    int n, p, q;

    cin >> n >> p >> q;

    int x, y;

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

        cin >> x >> y;

        v[x].pb(y);

    }

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

        sort(v[i].begin(), v[i].end());

    }



    while(q--){

        cin >> x >> y;

        int ans = 0;

        for(int i = x; i <= y; i++){

            ans += upper_bound(v[i].begin(), v[i].end(), y) - v[i].begin();

        }

        cout << ans << "\n";

    }

    return 0;

}


// Optimized solution to the same problem (faster):
#include <cstdio>

#include <cstring>

#include <algorithm>

void Unused(...) {}

#ifndef DEBUG

  #define echo(...) Unused(__VA_ARGS__)

#else

  #define echo(...) fprintf(stderr, __VA_ARGS__)

#endif



const int MaxN = 500 + 7;

const int MaxM = int(3e5) + 7;



struct Inv

{

    int l, r;

    int idx;

    friend bool operator<(const Inv &a, const Inv &b)

    {

        return a.l == b.l ? a.idx < b.idx : a.l > b.l;

    }

};

Inv rd[MaxM];



int n, m, q;

int ans[MaxM];



int vol[MaxN];

int lowbit(int x) { return x & (-x); }



int query(int v)

{

    int res = 0;

    for (; v > 0; v -= lowbit(v))

        res += vol[v];

    return res;

}

void update(int v)

{

    for (; v < MaxN; v += lowbit(v))

        ++vol[v];

}



int main()

{

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

    for (int i = 1; i <= m; ++i)

        scanf("%d %d", &rd[i].l, &rd[i].r);

    for (int i = 1; i <= q; ++i)

    {

        scanf("%d %d", &rd[i + m].l, &rd[i + m].r);

        rd[i + m].idx = i;

    }

    std::sort(rd + 1, rd + m + q + 1);



    for (int i = 1; i <= m + q; ++i)

    {

        // query

        if (rd[i].idx > 0)

            ans[rd[i].idx] = query(rd[i].r);

        else

            update(rd[i].r);

    }

    for (int i = 1; i <= q; ++i)

        printf("%d\n", ans[i]);



    return 0;

}




// Fastest known solution for this problem:
// Original C++ solution (slower):


#include<bits/stdc++.h>

#define ll long long

using namespace std;

const int N = 550;



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



int main() {

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

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

		int x, y; scanf("%d%d", &x, &y); ++ a[x][y];

	}

	for (int i = n; i >= 1; -- i) {

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

			b[i][j] = a[i][j] + b[i + 1][j] + b[i][j - 1] - b[i + 1][j - 1];

		}

	}

	

	while (Q --) {

		int x, y; scanf("%d%d", &x, &y);

		cout << b[x][y] << endl;

	}

	return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cmath>

#include<vector>

using namespace std;

int n,m,l,r,ans,q;

int a[1000][1000];

int main(){

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

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

		scanf("%d%d",&l,&r);

		a[l][r]++;

	}

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

		for (int j=1;j<=n;++j) a[i][j]+=a[i][j-1];

		

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

		scanf("%d%d",&l,&r);

		int ans=0;

		for (int j=l;j<=r;++j){

			ans+=a[j][r];

		}

		printf("%d\n",ans);

	}

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cstdio>

#include<algorithm>

using namespace std;

int n,m,q,a,b;

int dp[510][510];

int main() {

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

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

        scanf("%d%d",&a,&b);

        dp[a][b]++;

    }

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

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

            int k=i+j;

            dp[i][k]+=dp[i+1][k]+dp[i][k-1];

            if(j!=1)dp[i][k]-=dp[i+1][k-1];

        }

    }

    while(q--){

        scanf("%d%d",&a,&b);

        printf("%d\n",dp[a][b]);

    }

    return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cmath>

#include<vector>

using namespace std;

int n,m,l,r,ans,q;

int a[1000][1000];

int main(){

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

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

		scanf("%d%d",&l,&r);

		a[l][r]++;

	}

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

		for (int j=1;j<=n;++j) a[i][j]+=a[i][j-1];

		

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

		scanf("%d%d",&l,&r);

		int ans=0;

		for (int j=l;j<=r;++j){

			ans+=a[j][r];

		}

		printf("%d\n",ans);

	}

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

#define maxn 200008

int n,m,q;

int arr[maxn];

int sum[maxn];

int cha[maxn];

vector<int> v1[maxn];

int main(){

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

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

		int a,b;

		scanf("%d%d",&a,&b);

		v1[a].push_back(b);

	}

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

		sort(v1[i].begin(),v1[i].end());

	}

	int ans=0;

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

		int a,b;

		ans=0;

		scanf("%d%d",&a,&b);

		for(int j=a;j<=b;j++){

			ans+=upper_bound(v1[j].begin(),v1[j].end(),b)-v1[j].begin();

		}

		cout<<ans<<endl;

	}

	return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<algorithm>

#include<cmath>

#include<vector>

using namespace std;

int n,m,l,r,ans,q;

int a[1000][1000];

int main(){

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

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

		scanf("%d%d",&l,&r);

		a[l][r]++;

	}

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

		for (int j=1;j<=n;++j) a[i][j]+=a[i][j-1];

		

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

		scanf("%d%d",&l,&r);

		int ans=0;

		for (int j=l;j<=r;++j){

			ans+=a[j][r];

		}

		printf("%d\n",ans);

	}

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

int n,m,q,ans=0,x,y;

vector <int> a[10005];

int main()

{

	cin>>n>>m>>q;

	for (int i=1;i<=m;i++)

	{

		cin>>x>>y;

		a[x].push_back(y);

	}

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

	sort(a[i].begin(),a[i].end());

	for (int i=1;i<=q;i++)

	{

		ans=0;

		cin>>x>>y;

		for (int i=x;i<=y;i++)

		{

			ans+=upper_bound(a[i].begin(),a[i].end(),y)-a[i].begin();

		}

		cout<<ans<<endl;

	}

	return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<string.h>

#include<cmath>

#include<algorithm>

using namespace std;

#define INF 0x3f3f3f3f;

int che[505][505];

int road[505][505];

int main()

{

    int N,M,Q;

    scanf("%d %d %d",&N,&M,&Q);

    for(int i=1;i<=M;++i)

    {

        int l,r;

        scanf("%d%d",&l,&r);

        che[l][r]++;

    }

    for(int i=N;i>0;--i)

        for(int j=1;j<=N;++j)

        road[i][j]=che[i][j]+road[i][j-1]+road[i+1][j]-road[i+1][j-1];

    for(int i=1;i<=Q;++i)

    {

        int q,p;

        scanf("%d%d",&q,&p);

        printf("%d\n",road[q][p]);

    }

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<cstdio>

#include<iostream>

#include<algorithm>

#include<vector>

using namespace std;

int n,m,q,x,y,ans,xx;

vector <int> v[505];

int main(){

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

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

                scanf("%d%d",&x,&y);

                v[y].push_back(x);

        }

        for(int i=1;i<=n;i++) sort(v[i].begin(),v[i].end());

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

                scanf("%d%d",&x,&y);

                for(int i=x;i<=y;i++){

                        xx=lower_bound(v[i].begin(),v[i].end(),x)-v[i].begin();

                                ans+=v[i].size()-xx;

                    }

                printf("%d\n",ans);

                ans=0;

        }

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<string.h>

#include<cmath>

#include<algorithm>

using namespace std;

#define INF 0x3f3f3f3f;

int che[505][505];

int road[505][505];

int main()

{

    int N,M,Q;

    scanf("%d %d %d",&N,&M,&Q);

    for(int i=1;i<=M;++i)

    {

        int l,r;

        scanf("%d%d",&l,&r);

        che[l][r]++;

    }

    for(int i=N;i>0;--i)

        for(int j=1;j<=N;++j)

        road[i][j]=che[i][j]+road[i][j-1]+road[i+1][j]-road[i+1][j-1];

    for(int i=1;i<=Q;++i)

    {

        int q,p;

        scanf("%d%d",&q,&p);

        printf("%d\n",road[q][p]);

    }

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <cstdio>

#include <cstring>

#include <cmath>

#include <algorithm>

#include <vector>

using namespace std;

typedef long long LL;

inline LL in()

{

    LL x = 0, flag = 1; char ch = getchar();

    while (ch < '0' || ch > '9') {if (ch == '-') flag = -1; ch = getchar();}

    while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar();

    return x * flag;

}

vector <int> vec[600];

int n, m, q;

int main()

{

    n = in(), m = in(), q = in();

    for (int i = 1; i <= m; i ++)

    {

        int l = in(), r = in();

        vec[l].push_back(r);

    }

    for (int i = 1; i <= 500; i ++) sort(vec[i].begin(), vec[i].end());

    for (int i = 1; i <= q; i ++)

    {

        int l = in(), r = in(), ans = 0;

        for (int j = l; j <= r; j ++)

        {

            int pos = upper_bound(vec[j].begin(), vec[j].end(), r) - vec[j].begin();

            ans += pos;

            // cout << pos << endl;

        }

        cout << ans << endl;

    }

    return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<string.h>

#include<cmath>

#include<algorithm>

using namespace std;

#define INF 0x3f3f3f3f;

int che[505][505];

int road[505][505];

int main()

{

    int N,M,Q;

    scanf("%d %d %d",&N,&M,&Q);

    for(int i=1;i<=M;++i)

    {

        int l,r;

        scanf("%d%d",&l,&r);

        che[l][r]++;

    }

    for(int i=N;i>0;--i)

        for(int j=1;j<=N;++j)

        road[i][j]=che[i][j]+road[i][j-1]+road[i+1][j]-road[i+1][j-1];

    for(int i=1;i<=Q;++i)

    {

        int q,p;

        scanf("%d%d",&q,&p);

        printf("%d\n",road[q][p]);

    }

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cstdio>

#include<algorithm>

using namespace std;

int n,m,q;

int dp[502][502];

int main() {

    int a,b;

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

    for(int i = 0;i < m;i ++) {

        scanf("%d%d",&a,&b);

        dp[a][b] ++;

    }

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

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

            int k = i + j;

            dp[i][k] += dp[i + 1][k] + dp[i][k - 1];

            if(j > 1)dp[i][k] -= dp[i + 1][k - 1];

        }

    }

    for(int i = 0;i < q;i ++) {

        scanf("%d%d",&a,&b);

        printf("%d\n",dp[a][b]);

    }

    return 0;

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<string.h>

#include<cmath>

#include<algorithm>

using namespace std;

#define INF 0x3f3f3f3f;

int che[505][505];

int road[505][505];

int main()

{

    int N,M,Q;

    scanf("%d %d %d",&N,&M,&Q);

    for(int i=1;i<=M;++i)

    {

        int l,r;

        scanf("%d%d",&l,&r);

        che[l][r]++;

    }

    for(int i=N;i>0;--i)

        for(int j=1;j<=N;++j)

        road[i][j]=che[i][j]+road[i][j-1]+road[i+1][j]-road[i+1][j-1];

    for(int i=1;i<=Q;++i)

    {

        int q,p;

        scanf("%d%d",&q,&p);

        printf("%d\n",road[q][p]);

    }

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

using namespace std;

int info[505][505], raw[200005][2], quest[200005][2], ans[200005];

int main()

{

    int n, m, q;

    cin >> n >> m >> q;

    for ( int i = 0; i <= m-1; i++ )

    {

        cin >> raw[i][0] >> raw[i][1];

        info[raw[i][0]][raw[i][1]]++;

    }

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

    {

        for ( int j = 1; j <= n; j++ )

        {

            info[i][j] = info[i][j] + info[i][j-1];

        }

    }

    for ( int i = 0; i <= q-1; i++ )

    {

        cin >> quest[i][0] >> quest[i][1];

        for ( int j = quest[i][0]; j <= quest[i][1]; j++ )

        {

            ans[i] = ans[i] + info[j][quest[i][1]] - info[j][quest[i][0]-1];

        }

        cout << ans[i] << endl;

    }

}

// Optimized solution to the same problem (faster):
#include<cstdio>

#include<string.h>

#include<cmath>

#include<algorithm>

using namespace std;

#define INF 0x3f3f3f3f;

int che[505][505];

int road[505][505];

int main()

{

    int N,M,Q;

    scanf("%d %d %d",&N,&M,&Q);

    for(int i=1;i<=M;++i)

    {

        int l,r;

        scanf("%d%d",&l,&r);

        che[l][r]++;

    }

    for(int i=N;i>0;--i)

        for(int j=1;j<=N;++j)

        road[i][j]=che[i][j]+road[i][j-1]+road[i+1][j]-road[i+1][j-1];

    for(int i=1;i<=Q;++i)

    {

        int q,p;

        scanf("%d%d",&q,&p);

        printf("%d\n",road[q][p]);

    }

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

const int N=2e5+10;

struct E{

	int x,y,nxt,flag;

}mm[N<<2];

int h[N],len,p[N],n,ans[N],cur[N];

bool v[N];

inline int rd(){

	int x=0;int f=1;char s=getchar();

	while(!isdigit(s)) f=(s=='-'?-1:f),s=getchar();

	while(isdigit(s)) x=(x<<1)+(x<<3)+s-'0',s=getchar();

	return x*f;

}



inline void add(int x,int y){

	++len;

	mm[len].x=x;mm[len].y=y;mm[len].nxt=h[x];h[x]=len;

	++len;

	mm[len].x=y;mm[len].y=x;mm[len].nxt=h[y];h[y]=len;

	p[x]++;p[y]++;

	return ;

}

void dfs(int u,int f){

	for(int& k=h[u];k;k=mm[k].nxt){

		int y=mm[k].y;

		if(mm[k].flag||f==y) continue; 

		mm[k].flag=mm[k%2==0?k-1:k+1].flag=1;

		if(v[u] && u<=n && y>n) ans[u]=ans[y]=1; 

		if(v[u] && u>n && y<=n) ans[u]=ans[y]=-1;

		dfs(y,u);

	}

}

int main(){

//	freopen("t.in","r",stdin);

	n=rd();memset(h,0,sizeof h);

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

		int u=rd();u=max(0,u);

		add(u,i);

	}

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

		int u=rd();u=u==-1?0:(u+n);

		add(u,i+n);

	}

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

		if(p[i]%2) v[i]=1;

		else v[i]=0;

	}

	bool flag=true;

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

		if(v[i]!=v[i+n]) flag=0;

	if(flag) printf("POSSIBLE\n");

	else {

		printf("IMPOSSIBLE\n");

		return 0;

	}

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

		if(v[i]) add(i,i+n);//,printf("#%d %d\n",i,i+n);

	dfs(1,0);

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

	return 0;

}

// Optimized solution to the same problem (faster):
#include <iostream>

#include <cstdio>

#define il inline

#define ri register

#define Size 600050

using namespace std;

namespace{

	template<class free>

		il void read(free&x){

		x^=x;ri char c;while(c=getchar(),c==' '||c=='\n'||c=='\r');

		ri bool check(false);if(c=='-')check=true,c=getchar();

		while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();

		if(check)x=~x+1;

	}

	template<class f1,class...f2>

		il void read(f1&x,f2&...y){

		read(x),read(y...);

	}

}

struct point{

	int next,to;

}ar[Size];

bool is[Size];

int head[Size],art(1);

int son[2][Size],rt[2],a[Size];

il void link(int,int),dfs(int);

int main(){

	int n;read(n);

	for(int i(1),j;i<=n;++i)

		read(j),~j?link(j,i),

			++son[0][j]:rt[0]=i;

	for(int i(1),j;i<=n;++i)

		read(j),~j?link(j+n,i+n),

			++son[1][j]:rt[1]=i+n;

	link(rt[0],rt[1]);

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

		if(son[0][i]+son[1][i]&1)

			return puts("IMPOSSIBLE"),0;

		if(~son[0][i]&1)link(i,i+n),a[i]=art;

	}dfs(1),puts("POSSIBLE");

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

		if(son[0][i]&1)puts("0");

		else puts(is[a[i]]?"-1":"1");

	return 0;

}

il void dfs(int x){

	for(int i(head[x]);i;i=head[x])

		if(head[x]=ar[head[x]].next,!is[i])

			is[i^1]=1,dfs(ar[i].to);

}

il void link(int u,int v){

	ar[++art]={head[u],v},head[u]=art;

	ar[++art]={head[v],u},head[v]=art;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define range(i, a, b) for(int i = (a); i < (b); i++)

#define rep(i, a) range(i, 0, a)

using namespace std;

int d, n;

vector <int> a, e, r;

vector <vector <int>> memo;

const int INF = 1000000000;



void rec(int c = 0, int exp = 0, int end = d) {

	if (memo[exp][end] <= c) return;

	memo[exp][end] = c;



	rep (i, n) {

		if (exp < r[i]) continue;

		rec(c + 1, min(exp + e[i], 100), max(end - a[i], 0));

	}

}



int main() {

	while (cin >> d >> n, d) {

		a = e = r = vector <int> (n);

		rep (i, n) cin >> a[i] >> e[i] >> r[i];

		memo = vector <vector <int>> (105, vector <int> (105, INF));

		rec();

		int ans = INF;

		rep (i, 101) ans = min(ans, memo[i][0]);

		cout << (ans == INF ? "NA" : to_string(ans)) << endl;

	}

	return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#define range(i, a, b) for(int i = (a); i < (b); i++)

#define rep(i, a) range(i, 0, a)

using namespace std;

const int INF = 1000000000;



int main() {

	int d, n;

	while (cin >> d >> n, d) {

		int a[n], e[n], r[n];

		rep (i, n) cin >> a[i] >> e[i] >> r[i];

		//耐久値、経験値

		int dp[d + 1][101];

		rep (i, d + 1) rep (j, 101) dp[i][j] = INF;

		dp[d][0] = 0;

		for (int i = d; i >= 0; i--) rep (j, 101) {

			if (dp[i][j] == INF) continue;

			rep (k, n) {

				if (r[k] > j) continue;

				//a[i] -> 減る耐久値, e[i] -> 得る経験値

				dp[max(0, i - a[k])][min(100, j + e[k])] = min(dp[max(0, i - a[k])][min(100, j + e[k])],

																											 dp[i][j] + 1);

			}

		}

		int ans = INF;

		rep (i, 101) ans = min(ans, dp[0][i]);

		cout << (ans == INF ? "NA" : to_string(ans)) << endl;

	}

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <algorithm>

using namespace std;

int D, N, a[111], e[111], r[111], dp[111][111];

int main() {

	while (cin >> D >> N, D | N) {

		for (int i = 0; i < N; i++) cin >> a[i] >> e[i] >> r[i];

		int maxr = *max_element(r, r + N);

		for (int i = 0; i <= D; i++) fill(dp[i], dp[i] + maxr + 1, 999999999);

		dp[0][0] = 0;

		for (int i = 0; i < D; i++) {

			for (int j = 0; j <= maxr; j++) {

				for (int k = 0; k < N; k++) {

					if (j < r[k]) continue;

					int p = min(j + e[k], maxr), q = min(i + a[k], D);

					dp[q][p] = min(dp[q][p], dp[i][j] + 1);

				}

			}

		}

		int ret = *min_element(dp[D], dp[D] + maxr + 1);

		if (ret == 999999999) cout << "NA" << endl;

		else cout << ret << endl;

	}

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <algorithm>

#pragma warning(disable : 4996)

using namespace std;

int D, N, a[111], e[111], r[111], dp[111][111];

int main() {

	while (scanf("%d%d", &D, &N), D | N) {

		for (int i = 0; i < N; i++) scanf("%d%d%d", a + i, e + i, r + i);

		int maxr = *max_element(r, r + N);

		for (int i = 0; i <= D; i++) fill(dp[i], dp[i] + maxr + 1, 999999999);

		dp[0][0] = 0;

		for (int i = 0; i < D; i++) {

			for (int j = 0; j <= maxr; j++) {

				for (int k = 0; k < N; k++) {

					if (j < r[k]) continue;

					int p = min(j + e[k], maxr), q = min(i + a[k], D);

					dp[q][p] = min(dp[q][p], dp[i][j] + 1);

				}

			}

		}

		int ret = *min_element(dp[D], dp[D] + maxr + 1);

		if (ret == 999999999) puts("NA");

		else printf("%d\n", ret);

	}

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>

using namespace std;



#define rep(i, n) REP(i, 0, n)

#define ALL(v) v.begin(), v.end()

#define MSG(a) cout << #a << " " << a << endl;

#define REP(i, x, n) for (int i = x; i < n; i++)

#define OP(m) cout << m << endl

typedef long long ll;

typedef unsigned long long ull;



vector<int> g[200000];



int main()

{

    int n, m;

    cin >> n >> m;

    rep(i, m)

    {

        int a, b;

        cin >> a >> b;

        --a, --b;

        g[a].push_back(b);

        g[b].push_back(a);

    }

    int flag = 0;

    rep(i, g[0].size())

    {

        int v = g[0][i];

        if (find(ALL(g[v]), n - 1) != g[v].end())

            flag = 1;

    }

    flag == 1 ? OP("POSSIBLE") : OP("IMPOSSIBLE");



    return 0;

}

// Optimized solution to the same problem (faster):
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>

using namespace std;



#define rep(i, n) REP(i, 0, n)

#define ALL(v) v.begin(), v.end()

#define MSG(a) cout << #a << " " << a << endl;

#define REP(i, x, n) for (int i = x; i < n; i++)

#define OP(m) cout << m << endl

typedef long long ll;

typedef unsigned long long ull;



int main()

{

    int n, m;

    cin >> n >> m;



    bool a[n] = {}, b[n] = {};



    rep(i, m)

    {

        int to, from;

        cin >> to >> from;

        to--, from--;

        if (to == 0)

            a[from] = 1;

        if (from == n - 1)

            b[to] = 1;

    }



    rep(i, n)

    {

        if (a[i] == 1 && b[i] == 1)

        {

            OP("POSSIBLE");

            return 0;

        }

    }



    OP("IMPOSSIBLE");



    return 0;

}



/*vector<int> g[200000];



int main()

{

    int n, m;

    cin >> n >> m;

    rep(i, m)

    {

        int a, b;

        cin >> a >> b;

        --a, --b;

        g[a].push_back(b);

        g[b].push_back(a);

    }

    int flag = 0;

    rep(i, g[0].size())

    {

        int v = g[0][i];

        if (find(ALL(g[v]), n - 1) != g[v].end())

            flag = 1;

    }

    flag == 1 ? OP("POSSIBLE") : OP("IMPOSSIBLE");



    return 0;

}*/


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define N 100020

#define ll long long

using namespace std;

inline int read(){

	int x=0,f=1;char ch=getchar();

	while(ch>'9'||ch<'0')ch=='-'&&(f=0)||(ch=getchar());

	while(ch<='9'&&ch>='0')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();

	return f?x:-x;

}

std::map<int, bool> to1, to2;

int main(int argc, char const *argv[]) {

	int n = read(), m = read();

	while (m --) {

		int x = read(), y = read();

		if (x > y) swap(x, y);

		if (x == 1) to2[y] = 1;

		if (y == n) to1[x] = 1;

	}

	for (int i = 2; i < n; i++)

		if (to1[i] && to2[i])

			return puts("POSSIBLE")&0;

	puts("IMPOSSIBLE");

	return 0;

}


// Optimized solution to the same problem (faster):
#include<cmath>

#include<cstdio>

#include<cstdlib>

#include<map>

#include<cstring>

#include<algorithm>

#define ll long long

#define Max(x,y) ((x) > (y) ? (x) : (y))

#define Min(x,y) ((x) < (y) ? (x) : (y))

#define mod 1000000007

#define N 200010

using namespace std;

inline int read(){

	int x = 0,f = 1;char ch = getchar();

	while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}

	while(ch >= '0' && ch <= '9'){x = x*10+ch-'0';ch = getchar();}

	return x*f;

}



int n,m;

int nxt[N*2],to[N*2],head[N],cnt;



void add(int x,int y){

	to[++cnt] = y; nxt[cnt] = head[x]; head[x] = cnt;

	to[++cnt] = x; nxt[cnt] = head[y]; head[y] = cnt;

}



int main(){

	n = read(); m = read();

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

		int x = read(),y = read();

		add(x,y);

	}

	for(int i = head[1];i;i = nxt[i]){

		if(to[i] == n){

			puts("POSSIBLE");

			return 0;

		}

		for(int j = head[to[i]];j;j = nxt[j]){

			if(to[j] == n){

				puts("POSSIBLE");

				return 0;

			}

		}

	}

	puts("IMPOSSIBLE");

	return 0;

}

// Fastest known solution for this problem: