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