#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> S(N + 1, -1);
  int tmp;
  int tmps;
  int flag = 0;
  for (int i = 1; i <= M; i++) {
    cin >> tmp;
    cin >> tmps;
    if (S[tmp] != -1 and S[tmp] != tmps) {
      flag = 1;
    }
    S[tmp] = tmps;
  }
  int zf = 0;
  for (int i = 1; i <= N; i++) {
    if (S[i] == 0) {
      flag = 1;
    } else {
      zf = 1;
    }
    if (S[i] == -1) {
      S[i] = 0;
    }
  }
  if (flag == 0) {
    for (int i = 1; i <= N; i++) {
      cout << S[i];
    }
  } else {
    cout << -1;
  }
  return 0;
}
