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