#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<cctype>
#include<string.h>
#include <stdlib.h>

#define PI 3.1415926
void swap(int* x, int* y) {
	int a = *x;
	int b = *y;
	*x = b;
	*y = a;
}
int factorial(int n);
int sum(int n, int*);
int ave(int n, int*);
int min(int n, int*), min(int n, int m);
int max(int n, int*), max(int n, int m);

int main() {
	int N, K, B[200] = { 0 },A;
	int X[200][10] = { 0 }, Y[10] = { 0 };
	scanf("%d %d", &N, &K);
	for (int i = 1; i <= K; i++) {
		scanf("%d", &A);
		scanf("%d", &B[A]);
	}
	/*
	for (int i = 1; i <= N; i++) {
		printf("%d %d\n", i, B[i]);
	}
	*/
	
	if (B[1] == 0) {
		X[1][1] = 1;
		X[1][2] = 1;
		X[1][3] = 1;
	}
	else if(B[1] == 1) {
		X[1][1] = 1;
	}
	else if (B[1] == 2) {
		X[1][2] = 1;
	}
	else if (B[1] == 3) {
		X[1][3] = 1;
	}
	if (B[2] == 0) {
		X[2][1] = X[1][1] + X[1][2] + X[1][3];
		X[2][2] = X[1][1] + X[1][2] + X[1][3];
		X[2][3] = X[1][1] + X[1][2] + X[1][3];
	}
	else if (B[2] == 1) {
		X[2][1] = X[1][1] + X[1][2] + X[1][3];;
	}
	else if (B[2] == 2) {
		X[2][2] = X[1][1] + X[1][2] + X[1][3];;
	}
	else if (B[2] == 3) {
		X[2][3] = X[1][1] + X[1][2] + X[1][3];;
	}
	for (int i = 3; i <= N; i++) {
		//printf("%d %d\n", i, B[i]);
		if (B[i] == 0) {
			X[i][1] = X[i - 1][2] + X[i - 1][3] + X[i - 2][2] + X[i - 2][3];
			X[i][2] = X[i - 1][3] + X[i - 1][1] + X[i - 2][3] + X[i - 2][1];
			X[i][3] = X[i - 1][1] + X[i - 1][2] + X[i - 2][1] + X[i - 2][2];
			if (X[i - 1][1] == 0) {
				X[i][1] -= X[i - 2][2] + X[i - 2][3];
			}
			if (X[i - 1][2] == 0) {
				X[i][2] -= X[i - 2][3] + X[i - 2][1];
			}
			if (X[i - 1][3] == 0) {
				X[i][3] -= X[i - 2][1] + X[i - 2][2];
			}
		}
		else if (B[i] == 1) {
			X[i][1] = X[i - 1][2] + X[i - 1][3] + X[i - 2][2] + X[i - 2][3];
			X[i][2] = 0;
			X[i][3] = 0;
			if (X[i - 1][1] == 0) {
				X[i][1] -= X[i - 2][2] + X[i - 2][3];
			}
		}
		else if (B[i] == 2) {
			X[i][1] = 0;
			X[i][2] = X[i - 1][3] + X[i - 1][1] + X[i - 2][3] + X[i - 2][1];
			X[i][3] = 0;
			if (X[i - 1][2] == 0) {
				X[i][2] -= X[i - 2][3] + X[i - 2][1];
			}
		}
		else if (B[i] == 3) {
			X[i][1] = 0;
			X[i][2] = 0;
			X[i][3] = X[i - 1][1] + X[i - 1][2] + X[i - 2][1] + X[i - 2][2];
			if (X[i - 1][3] == 0) {
				X[i][3] -= X[i - 2][1] + X[i - 2][2];
			}
		}
		X[i][1] %= 10000;
		X[i][2] %= 10000;
		X[i][3] %= 10000;
	}
	/*
	for (int i = 1; i <= N; i++) {
		printf("%d %d %d\n", X[i][1], X[i][2], X[i][3]);
	}
	*/
	printf("%d\n", (X[N][1] + X[N][2] + X[N][3])%10000);
	return 0;
}

int factorial(int n) {
	if (n > 0) {
		return n * factorial(n - 1);
	}
	else {
		return 1;
	}
}
int sum(int n, int *all) {
	int total = 0;
	for (int i = 0; i < n; ++i) {
		total += all[i];
	}
	return total;
}
int ave(int n, int *all) {
	int total = 0;
	for (int i = 0; i<n; ++i) {
		total += all[i];
	}
	return total / n;
}
int min(int n, int *all) {

	int min = all[0];
	for (int i = 1; i < n; ++i) {
		if (all[0] > all[i]) {
			min = all[i];
		}
	}
	return min;
}
int max(int n, int *all) {
	int max = all[0];
	for (int i = 1; i<n; ++i) {
		if (all[0]<all[i]) {
			max = all[i];
		}
	}
	return max;
}
int max(int n, int m) {
	if (n >= m) {
		return n;
	}
	else {
		return m;
	}
}
int min(int n, int m) {
	if (n >= m) {
		return m;
	}
	else {
		return n;
	}
}

Measured memory_bytes: 2716