#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int d[4];
  for (int i = 0; i < 4; i++) {
    d[i] = -1;
  }
  for (int m = 0; m < M; m++) {
    int s, c;
    cin >> s >> c;
    if (d[s - 1] != -1 && d[s - 1] != c) {
      cout << "-1";
      return 0;
    } else {
      d[s - 1] = c;
    }
  }
  if (d[0] == 0) {
    cout << "-1";
    return 0;
  }
  int l;
  for (l = 3; d[l] == -1; l--)
    ;
  if (d[0] == -1) {
    cout << 1;
  } else {
    cout << d[0];
  }
  for (int i = 1; i <= l; i++) {
    if (d[i] != -1) {
      cout << d[i];
    } else {
      cout << 0;
    }
  }
  return 0;
}
