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