#include <bits/stdc++.h>
using namespace std;
int n, m;
struct indata {
  int s;
  int c;
};
bool cmp(const indata &a, const indata &b) { return a.s < b.s; }
int main() {
  cin >> n >> m;
  vector<int> s(m, 0);
  vector<int> c(m, 0);
  vector<indata> sc(m);
  for (int i = 0; i < m; ++i) {
    cin >> sc.at(i).s >> sc.at(i).c;
  }
  sort(sc.begin(), sc.end(), cmp);
  int now = 0;
  vector<int> ans(n, 0);
  ans.at(0) = 11;
  for (int i = 1; i <= n; ++i) {
    if (now < m && sc.at(now).s == i) {
      int ansb = sc.at(now).c;
      now++;
      while (now < m && sc.at(now).s == i) {
        if (ansb != sc.at(now).c) {
          ans.at(i - 1) = 10;
          break;
        }
        now++;
      }
      if (ans.at(i - 1) != 10) ans.at(i - 1) = ansb;
    }
  }
  bool flg = true;
  for (int i = 0; i < n; ++i) {
    if (ans.at(i) == 10) flg = false;
  }
  if (flg) {
    bool zflg = true;
    for (int i = 0; i < n; ++i) {
      if (i == 0) {
        if (ans.at(0) == 11) {
          zflg = false;
          cout << 1;
        } else if (ans.at(0) == 0) {
        } else {
          zflg = false;
          cout << ans.at(i);
        }
      } else {
        if (zflg) {
        } else {
          zflg = false;
          cout << ans.at(i);
        }
      }
    }
    if (zflg) cout << -1;
    cout << endl;
  } else {
    cout << -1 << endl;
  }
}
