#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int32_t, int32_t>;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int64_t N, M;
  cin >> N >> M;
  vector<int32_t> lookup(N + 1, -1);
  bool is_okay = true;
  for (int32_t i = 0; i < M; ++i) {
    int32_t s, c;
    cin >> s >> c;
    if (lookup[s] > 0 && lookup[s] != c) {
      is_okay = false;
      break;
    } else if (s == 1 && c == 0) {
      is_okay = false;
      break;
    } else {
      lookup[s] = c;
    }
  }
  if (is_okay) {
    for (int32_t i = 1; i <= N; ++i) {
      if (lookup[i] > 0) {
        cout << lookup[i];
      } else {
        if (i == 0 && N > 1) {
          cout << 1;
        } else {
          cout << 0;
        }
      }
    }
    cout << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
