#include <cstdio>

int n, m;
int a[5];

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++i) a[i] = -1;
    for (int i = 1, x, y; i <= m; ++i) {
        scanf("%d%d", &x, &y);
        if (~a[x] && a[x] ^ y) return puts("-1"), 0;
        a[x] = y;
    }
    if (n == 1) return printf("%d\n", ~a[1] ? a[1] : 0), 0;
    if (!a[1]) return puts("-1"), 0;
    for (int i = 1; i <= n; ++i) printf("%d", ~a[i] ? a[i] : (i == 1 ? 1 : 0));
    return 0;
}
