#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> num(N, -1);
  auto valid = true;
  for (auto i = 0; i < M; ++i) {
    int s, c;
    cin >> s >> c;
    --s;
    if (c == 0 && s == 0) {
      valid = false;
    } else if (num[s] < 0) {
      num[s] = c;
    } else if (num[s] != c) {
      valid = false;
    }
  }
  if (valid == false) {
    cout << -1 << endl;
  } else {
    for (auto i = 0; i < N; ++i) {
      if (num[i] < 0) {
        if (i == 0 && N > 1) {
          num[i] = 1;
        } else {
          num[i] = 0;
        }
      }
      cout << num[i];
    }
    cout << endl;
  }
  return 0;
}
