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