#include <cstdio>

using namespace std;

int a[10];

int main() {
    int n, m;
    scanf("%d%d", &n, &m);// don't forget &
    for (int i = 1; i <= n; i++) {
        a[i] = -1;
    }
    bool f = true;
    while (m--) {
        int x, y;
        scanf("%d%d", &x, &y);// don't forget &
        if (a[x] != -1 && a[i] != y) {
            f = false;
            continue;
        }
        a[x] = y;
    }
    if (n != 1 && a[1] <= 0) {
        f = false;
    }
    if (!f) {
        puts("-1");
    }else {
        for (int i = 1; i <= n; i++) {
            if (a[i] == -1) {
                a[i] = 0;
            }
            printf("%d", a[i]);
        }
    }
    
    return 0;
}
