#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  int M;
  cin >> N >> M;
  vector<int> num(N, -1);
  bool exist = true;
  for (int i = 0; i < M; i++) {
    int s;
    int c;
    cin >> s >> c;
    if (num[s - 1] == -1) {
      num[s - 1] = c;
    } else if (num[s - 1] != c) {
      exist = false;
    }
  }
  if (num[0] == 0 && N != 1) {
    exist = false;
  }
  if (exist) {
    int intnum = 0;
    for (int i = 0; i < N; i++) {
      intnum *= 10;
      if (num[i] == -1) {
        if (i == 0) {
          num[i] = 1;
        } else {
          num[i] = 0;
        }
      }
      intnum += num[i];
    }
    cout << intnum << endl;
  } else {
    cout << -1 << endl;
  }
}
