#include <bits/stdc++.h>
using namespace std;
using ipair = pair<int, int>;
long long INF = 1e16 + 7;
bool operator>(const ipair a, const ipair b) { return a.first > b.first; }
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> ans(3);
  if (N == 1) {
    ans[0] = 0;
    ans[1] = 0;
    ans[2] = 1;
  } else if (N == 2) {
    ans[0] = 0;
    ans[1] = 1;
    ans[2] = 0;
  } else {
    ans[0] = 1;
    ans[1] = 0;
    ans[2] = 0;
  }
  vector<int> cond(N + 1, -1);
  for (int i = 0; i < (M); ++i) {
    int s, c;
    cin >> s >> c;
    s--;
    if (c == 0 && N - 1 == s) {
      cout << -1 << endl;
      return 0;
    }
    if (cond[s] != -1 && cond[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    cond[s] = c;
    ans[s] = c;
  }
  for (int i = (3 - N); i < 3; i++) {
    cout << ans[i];
  }
  cout << endl;
  return 0;
}
