int main(){
    int Flg = 0;

    int N, M;
    cin >> N >> M;

    int range_1 = pow(10, N-1);
    int range_2 = pow(10, N);
    
    int s[M];
    int c[M];

    for (int i=0;i<M;i++){
        cin >> s[i] >> c[i];
    }
    for (int i=range_1-1; i < range_2; i++){
        int x = i;
        int num[3] = {-1,-1,-1};
        int count = 0;

        while(true){
            int r = x % 10;//余り
            int q = x / 10;//商

            num[count] = r;

            x = q;
            if(q==0) break;
            ++count;
        }

        int a = num[0];
        num[0] = num[2];
        num[2] = a;

        for (int i=0;i<M;i++){
            if (num[s[i]-1] == c[i]) Flg = 1;
            else {
                Flg = 2;
                break;
            }
        }

        if(Flg == 1){
            cout << i;
            break;
        }
    }
    if(Flg == 2){
        cout << -1;
    }

    return 0;
}