#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> vec(N + 1);
  vector<int> vecS(M), vecC(M);
  int f = 0;
  if (N == 1) {
    int s, c;
    cin >> s >> c;
    cout << c << endl;
    return 0;
  }
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    vecS.at(i) = s;
    vecC.at(i) = c;
    if (s == 1 && c == 0) f++;
    vec.at(s) = c;
  }
  for (int i = 0; i < M - 1; i++) {
    for (int j = i + 1; j < M; j++) {
      if (vecS.at(i) == vecS.at(j)) {
        if (vecC.at(i) != vecC.at(j)) f++;
      }
    }
  }
  if (f > 0) {
    cout << "-1" << endl;
    return 0;
  }
  if (vec.at(1) == 0) vec.at(1) = 1;
  for (int i = 1; i <= N; i++) {
    cout << vec.at(i);
  }
}
