#include <bits/stdc++.h>
using namespace std;
int main(void) {
  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];
  }
  vector<int> datas(3, -1);
  for (int i = 0; i < m; i++) {
    if (datas[s[i] - 1] == -1) {
      datas[s[i] - 1] = c[i];
    } else if (datas[s[i] - 1] != c[i]) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (n == 1) {
    cout << datas[0] << endl;
    return 0;
  }
  bool isZeroOk = false;
  for (int i = 0; i < n; i++) {
    if (datas[i] == 0 && !isZeroOk) {
      cout << -1 << endl;
      return 0;
    } else {
      if (datas[i] == -1) {
        if (isZeroOk) {
          cout << 0;
        } else {
          cout << 1;
          isZeroOk = true;
        }
      } else {
        cout << datas[i];
        isZeroOk = true;
      }
    }
  }
  cout << endl;
  return 0;
}
