#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
const double PI = acos(-1.0);
const long long MOD = 1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > c(m);
  vector<bool> cnt(n, false);
  for (int i = 0; i < (m); i++) {
    int x, y;
    cin >> x >> y;
    c[i] = make_pair(x, y);
    cnt[x - 1] = true;
  }
  bool flg = true;
  sort(c.begin(), c.end());
  for (int i = 0; i < (m); i++) {
    if (c[i].first == 1 && c[i].second == 0) {
      flg = false;
      break;
    }
    for (int j = 0; j < (m); j++) {
      if (c[i].first == c[j].first && c[i].second != c[j].second) {
        flg = false;
        break;
      }
    }
  }
  if (flg == false) {
    cout << -1 << endl;
  } else {
    for (int i = 0; i < (n); i++) {
      if (cnt[i] == true) {
        for (int j = 0; j < (m); j++) {
          if (c[j].first == i + 1) {
            cout << c[j].second;
            break;
          }
        }
      } else {
        if (i == 0)
          cout << 1;
        else
          cout << 0;
      }
    }
    cout << endl;
  }
}
