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