Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var scanner = bufio.NewScanner(os.Stdin)

// 文字列を1行取得
func StrStdin() (stringReturned string) {
//	scanner := bufio.NewScanner(os.Stdin)

	scanner.Scan()
	stringInput := scanner.Text()

	stringReturned = strings.TrimSpace(stringInput)
	return
}

// 整数値1つ取得
func IntStdin() (int, error) {
	stringInput := StrStdin()
	return strconv.Atoi(strings.TrimSpace(stringInput))
}

// 空白や空文字だけの値を除去したSplit()
func SplitWithoutEmpty(stringTargeted string, delim string) (stringReturned []string) {
	stringSplited := strings.Split(stringTargeted, delim)

	for _, str := range stringSplited {
		if str != "" {
			stringReturned = append(stringReturned, str)
		}
	}

	return
}

// デリミタで分割して文字列スライスを取得
func SplitStrStdin(delim string) (stringReturned []string) {
	// 文字列で1行取得
	stringInput := StrStdin()

	// 空白で分割
	// stringSplited := strings.Split(stringInput, delim)
	stringReturned = SplitWithoutEmpty(stringInput, delim)

	return
}

// デリミタで分割して整数値スライスを取得
func SplitIntStdin(delim string) (intSlices []int, err error) {
	// 文字列スライスを取得
	stringSplited := SplitStrStdin(" ")

	// 整数スライスに保存
	for i := range stringSplited {
		var iparam int
		iparam, err = strconv.Atoi(stringSplited[i])
		if err != nil {
			return
		}
		intSlices = append(intSlices, iparam)
	}
	return
}

func main() {
	nk, _ := SplitIntStdin(" ")
	n, k := nk[0], nk[1]
	kind := make([]int, n)
	for i := 0; i < k; i++ {
		var tmp []int
		var err error
		if tmp, err = SplitIntStdin(" "); err != nil {
			panic(err)
		}
		kind[tmp[0]-1] = tmp[1]
	}
	dp := make([][3][3]int, n)
	if kind[0] > 0 {
		dp[0][0][kind[0]-1] = 1
	} else {
		for i := 0; i < 3; i++ {
			dp[0][0][i] = 1
		}
	}
	if kind[1] > 0 {
		for i := 0; i < 3; i++ {
			dp[1][i][kind[1]-1] = dp[0][0][i]
		}
	} else {
		for i := 0; i < 3; i++ {
			for j := 0; j < 3; j++ {
				dp[1][i][j] = dp[0][0][i]
			}
		}
	}
	for i := 1; i < n-1; i++ {
		if kind[i+1] > 0 {
			for j := 0; j < 3; j++ {
				if j == kind[i+1]-1 {
					for k := 0; k < 3; k++ {
						if j != k {
							dp[i+1][j][kind[i+1]-1] += dp[i][k][j]
							dp[i+1][j][kind[i+1]-1] %= 10000
						}
					}
				} else {
					for k := 0; k < 3; k++ {
						dp[i+1][j][kind[i+1]-1] += dp[i][k][j]
						dp[i+1][j][kind[i+1]-1] %= 10000
					}
				}
			}
		} else {
			for j := 0; j < 3; j++ {
				for k := 0; k < 3; k++ {
					for l := 0; l < 3; l++ {
						if j != k || k != l {
							dp[i+1][k][j] += dp[i][l][k]
							dp[i+1][k][j] %= 10000
						}
					}
				}
			}
		}
	}
	result := 0
	for i := 0; i < 3; i++ {
		for j := 0; j < 3; j++ {
			result += dp[n-1][i][j]
		}
	}
	// fmt.Println(dp)
	// fmt.Println(kind)
	fmt.Println(result % 10000)
}

C++: #include <bits/stdc++.h>
#define int long long
#define double long double
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define fcout(n) cout << fixed << setprecision(n)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acosl(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> inline bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


template <uint_fast64_t Modulus>
struct ModInt {
    using u64 = uint_fast64_t;
    u64 val;
    constexpr ModInt(const int x = 0) noexcept : val(x >= 0 ? x%Modulus : x%(int)Modulus+Modulus){}
    constexpr const u64& value() const noexcept { return val; }
    constexpr ModInt operator-() const noexcept { return val ? Modulus-val : 0; }
    constexpr ModInt operator+(const ModInt& rhs) const noexcept { return ModInt(*this) += rhs; }
    constexpr ModInt operator-(const ModInt& rhs) const noexcept { return ModInt(*this) -= rhs; }
    constexpr ModInt operator*(const ModInt& rhs) const noexcept { return ModInt(*this) *= rhs; }
    constexpr ModInt operator/(const ModInt& rhs) const noexcept { return ModInt(*this) /= rhs; }
    constexpr bool operator==(const ModInt& rhs) const noexcept { return val == rhs.val; }
    constexpr bool operator!=(const ModInt& rhs) const noexcept { return val != rhs.val; }
    constexpr ModInt& operator+=(const ModInt& rhs) noexcept {
        val += rhs.val;
        if(val >= Modulus) val -= Modulus;
        return *this;
    }
    constexpr ModInt& operator-=(const ModInt& rhs) noexcept {
        if(val < rhs.val) val += Modulus;
        val -= rhs.val;
        return *this;
    }
    constexpr ModInt& operator*=(const ModInt& rhs) noexcept {
        val = val*rhs.val%Modulus;
        return *this;
    }
    constexpr ModInt& operator/=(const ModInt& rhs) noexcept {
        *this *= rhs.inverse();
        return *this;
    }
    constexpr ModInt inverse() const noexcept {
        int a = val, b = Modulus, u = 1, v = 0;
        while(b){
            int t = a/b;
            a -= t*b; swap(a, b);
            u -= t*v; swap(u, v);
        }
        return ModInt(u);
    }
    constexpr ModInt pow(u64 n) const noexcept {
        ModInt res(1), mul(val);
        while(n > 0){
            if(n&1) res *= mul;
            mul *= mul;
            n >>= 1;
        }
        return res;
    }
    friend constexpr ModInt operator+(const int lhs, const ModInt& rhs) noexcept { return rhs+lhs; }
    friend constexpr ModInt operator*(const int lhs, const ModInt& rhs) noexcept { return rhs*lhs; }
    friend ostream& operator<<(ostream& os, const ModInt& rhs){ return os << rhs.val; }
    friend istream& operator>>(istream& is, ModInt& rhs){
        u64 t;
        is >> t;
        rhs = ModInt<Modulus>(t);
        return is;
    }
};
using modint = ModInt<10000>;


int N, K;
int sch[110];
modint dp[110][3][2];


signed main(){
    cin >> N >> K;
    fill(sch, sch+N+1, -1);
    rep(i, 0, K){
        int A, B;
        cin >> A >> B;
        B--;
        sch[A] = B;
    }

    if(sch[1] == -1) rep(i, 0, 3) dp[1][i][0] = 1;
    else dp[1][sch[1]][0] = 1;
    repe(i, 2, N){
        if(sch[i] == -1){
            rep(j, 0, 3){
                dp[i][j][0] += dp[i-1][(j+1)%3][0]+dp[i-1][(j+1)%3][1]+dp[i-1][(j+2)%3][0]+dp[i-1][(j+2)%3][1];
                dp[i][j][1] += dp[i-1][j][0];
            }
        }
        else {
            int j = sch[i];
            dp[i][j][0] += dp[i-1][(j+1)%3][0]+dp[i-1][(j+1)%3][1]+dp[i-1][(j+2)%3][0]+dp[i-1][(j+2)%3][1];
            dp[i][j][1] += dp[i-1][j][0];
        }
    }

    modint ans = 0;
    rep(i, 0, 3) rep(j, 0, 2) ans += dp[N][i][j];

    cout << ans << endl;

    return 0;
}