#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<pair<int, int> > P(M);
  for (int i = 0; i < (int)(M); i++) {
    int s, c;
    cin >> s >> c;
    P[i] = make_pair(s, c);
  }
  sort(P.begin(), P.end());
  P.erase(unique(P.begin(), P.end()), P.end());
  int len = P.size();
  if (N == 1) {
    if (P[0].second == 0) {
      cout << -1 << endl;
    } else {
      cout << P[0].second << endl;
    }
    return 0;
  }
  string ans[N];
  for (int i = 0; i < (int)(N); i++) ans[i] = "-1";
  for (int i = 0; i < (int)(len); i++) {
    if (P[i].first == 1 && P[i].second == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (ans[P[i].first - 1] != "-1") {
      cout << -1 << endl;
      return 0;
    }
    ans[P[i].first - 1] = to_string(P[i].second);
  }
  if (ans[0] == "-1") ans[0] = 1;
  if (N >= 2) {
    for (int i = 1; i < N; i++) {
      if (ans[i] == "-1") ans[i] = '0';
    }
  }
  for (int i = 0; i < (int)(3); i++) {
    cout << ans[i];
  }
  cout << endl;
  return 0;
}
