#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> v(N);
  v.assign(N, -1);
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (N > 1 && s == 1 && c == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (v[s - 1] == -1 || v[s - 1] == c) {
      v[s - 1] = c;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int x : v) {
    cout << ((x == -1) ? 0 : x);
  }
}
