#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a[3];
  for (int i = 0; i < (3); i++) a[i] = -1;
  for (int i = 0; i < (m); i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (a[s] != c && a[s] != -1) {
      cout << -1 << endl;
      return 0;
    }
    a[s] = c;
  }
  for (int i = 0; i < (3); i++) {
    if (n >= 3 - i) {
      if (a[i] == -1) {
        if (n == 3 - i && n != 1)
          a[i] = 1;
        else
          a[i] = 0;
      } else if (a[i] == 0 && n == 3 - i && n != 1) {
        cout << -1 << endl;
        return 0;
      }
    } else {
      if (a[i] != -1) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  for (int i = 0; i < (3); i++) {
    if (n >= 3 - i) cout << a[i];
  }
  return 0;
}
