#include <bits/stdc++.h>
using namespace std;
unsigned GetDigit(unsigned num) {
  unsigned digit = 0;
  while (num != 0) {
    num /= 10;
    digit++;
  }
  return digit;
}
int main() {
  int N, M, i, num;
  bool b = false;
  cin >> N >> M;
  map<int, int> t;
  for (i = 0; i < M; ++i) {
    int k, v;
    cin >> k >> v;
    if (t.count(k)) {
      if (t[k] != v) {
        b = true;
        break;
      }
    } else {
      t[k] = v;
    }
  }
  if (b)
    cout << "-1";
  else {
    for (i = 1; i <= N; ++i) {
      if (N - i == 2)
        num += t[i] * 100;
      else if (N - i == 1)
        num += t[i] * 10;
      else
        num += t[i];
    }
    int d;
    d = GetDigit(num);
    if (N != 1 && num == 0) {
      cout << "-1";
    } else if (N != d) {
      if (!(t.count(1))) {
        if (N == 2) {
          num += 10;
          cout << num;
        } else if (N == 3) {
          num += 100;
          cout << num;
        }
      } else
        cout << "-1";
    } else
      cout << num;
  }
}
