#include <bits/stdc++.h>
using namespace std;
int N, M, s[3], c[5], hss[4], a, b;
bool flag = true;
int main() {
  cin >> N >> M;
  while (M--) {
    cin >> a >> b;
    if (N != 1) {
      if (a == 1 && b == 0) {
        flag = false;
      }
    }
    if (hss[a]) {
      if (s[a] != b) {
        flag = false;
      }
    } else {
      s[a] = b;
      hss[a]++;
    }
  }
  if (flag) {
    if (N != 1) {
      if (!s[1]) {
        s[1] = 1;
      }
    }
    for (int i = 1; i <= N; i++) {
      cout << s[i];
    }
    cout << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
