#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  vector<int> A(N);
  int C = 0;
  int ans = 0;
  int CC = 0;
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
    if (i > 0) {
      if (s[i] == s[i - 1]) {
        if (c[i] != c[i - 1]) {
          C++;
        }
      }
    }
    if (s[i] == 1 && c[i] == 0) {
      CC++;
    }
  }
  for (int i = 0; i < M; i++) {
    A[s[i] - 1] = c[i];
  }
  if (N > 1) {
    if (A[0] == 0 && CC == 0) {
      A[0] = 1;
    }
  }
  if (M == 0) {
    cout << -1;
  } else if (C > 0) {
    cout << -1;
  } else if (A[0] == 0) {
    for (int i = 0; i < N; i++) {
      ans += A[i];
    }
    if (ans == 0) {
      cout << -1;
    } else {
      for (int i = 1; i < N; i++) {
        if (A[i] != 0) {
          cout << A[i];
        } else {
          cout << A[i + 1];
          break;
        }
      }
    }
  } else {
    for (int i = 0; i < N; i++) {
      cout << A[i];
    }
  }
  cout << endl;
}
