#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, s, c;
  bool ans = true, z = false;
  cin >> N >> M;
  int a[N];
  for (int i = 0; i < N; i++) {
    a[i] = -1;
  }
  for (int i = 0; i < M; i++) {
    cin >> s >> c;
    s = s - 1;
    if (a[s] == -1)
      a[s] = c;
    else if (a[s] != c) {
      ans = false;
    }
  }
  if (a[0] == 0) ans = false;
  if ((a[0] == 0 || a[0] == -1) && a[1] == -1 && a[2] == -1 && N == 1) {
    ans = true;
    z = true;
  }
  for (int i = 0; i < N; i++) {
    if (a[i] == -1 && i != 0)
      a[i] = 0;
    else if (a[i] == -1 && i == 0)
      a[i] = 1;
  }
  if (ans) {
    if (not z) {
      for (int i = 0; i < N; i++) {
        cout << a[i];
      }
    } else
      cout << 0;
  } else
    cout << -1;
  cout << endl;
  return 0;
}
