#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(N, -1);
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (c == A.at(s)) continue;
    if (A.at(s) == -1)
      A.at(s) = c;
    else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (1 == N)
    if (-1 == A.at(0)) {
      cout << 0 << endl;
      return 0;
    }
  if (1 != N)
    if (0 == A.at(0)) {
      cout << -1 << endl;
      return 0;
    }
  if (-1 == A.at(0)) A.at(0) = 1;
  for (int i = 1; i < M; i++)
    if (-1 == A.at(i)) A.at(i) = 0;
  for (int i = 0; i < M; i++) cout << A.at(i);
  cout << endl;
  return 0;
}
