#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int answer = 0;
  int base = 1;
  vector<int> a(n, -1);
  for (int _ = 0; _ < (m); ++_) {
    int s, c;
    cin >> s >> c;
    int j = n - s;
    if (a[j] != -1 && a[j] != c) {
      answer = -1;
      goto answer;
    }
    a[j] = c;
  }
  for (int i = 0; i < (n); ++i) {
    if (a[i] == -1) {
      if (i == n - 1)
        a[i] = 1;
      else
        a[i] = 0;
    }
  }
  if (n != 1 && a[n - 1] == 0) {
    answer = -1;
    goto answer;
  }
  for (int i = 0; i < (n); ++i) {
    answer += a[i] * base;
    base *= 10;
  }
answer:
  cout << answer << endl;
}
