#include <bits/stdc++.h>
using namespace std;
const long mod = 1e9 + 7;
const int size = 1e4;
const long inf = 1e9;
int main() {
  int N, M;
  cin >> N >> M;
  int s, c;
  int A[N];
  for (int i = 0; i < N; i++) A[i] = -1;
  for (int i = 0; i < M; i++) {
    cin >> s >> c;
    s--;
    if (A[s] == -1)
      A[s] = c;
    else if (A[s] != c) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (N > 1 && A[0] == -1)
    A[0] = 1;
  else
    A[0] = 0;
  for (int i = 1; i < N; i++)
    if (A[i] == -1) A[i] = 0;
  if (N > 1 && A[0] == 0) {
    cout << -1 << endl;
  } else {
    for (int i = 0; i < N; i++) cout << A[i];
    cout << endl;
  }
}
