#include <bits/stdc++.h>
using namespace std;
int N[10];
int main() {
  memset(N, -1, sizeof N);
  int n, m;
  cin >> n >> m;
  while (m--) {
    int pos, x;
    cin >> pos >> x;
    if (N[pos] == -1) {
      N[pos] = x;
    } else {
      if (N[pos] != x) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  if (n == 1) {
    cout << N[1] << endl;
    return 0;
  }
  if (n == 2) {
    if (N[1] != 0) {
      if (N[1] == -1) N[1] = 1;
      if (N[2] == -1) N[2] = 0;
      cout << N[1] << N[2] << endl;
    } else {
      cout << -1 << endl;
    }
    return 0;
  }
  if (n == 3) {
    if (N[1] != 0) {
      if (N[1] == -1) N[1] = 1;
      if (N[2] == -1) N[2] = 0;
      if (N[3] == -1) N[3] = 0;
      cout << N[1] << N[2] << N[3] << endl;
    } else {
      cout << -1 << endl;
    }
    return 0;
  }
  return 0;
}
