#include <iostream>
using namespace std;

int main() {
    int n, m; cin >> n >> m;
    int A[n+1] = {};
    int flag = 0;
    int sum = 0;
    for (int i = 0; i < m; i++) {
        int s, c; cin >> s >> c;
        if (A[s-1] != c && A[s-1] != 0) flag = 1;
        else A[s-1] = c; sum += c;
    }
    if (flag || (sum == 0 && n != 1))  { puts("-1"); return 0; }
    for (int i = 0; i < n; i++) cout << A[i];
    cout << endl;
}