#include <bits/stdc++.h>
using namespace std;
const double pi = 3.14159265358979323846;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N, M;
  cin >> N >> M;
  long long s[M], c[M];
  for (long long i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  if (M == 0) {
    cout << -1 << endl;
    return 0;
  }
  long long len = 0;
  if (N == 1) len = 9;
  if (N == 2) len = 99;
  if (N == 3) len = 999;
  bool bingo2 = true;
  if (N == 1) {
    for (long long i = 0; i < M; i++) {
      if (c[i] != 0) {
        bingo2 = false;
      }
    }
    if (bingo2) {
      cout << 0 << endl;
      return 0;
    }
  }
  string second;
  long long slen;
  bool bingo;
  long long bingoNum = 1000;
  for (long long i = 0; i <= len; i++) {
    second = to_string(i);
    slen = second.length();
    bingo = true;
    for (long long i = 0; i < M; i++) {
      if (slen != N) {
        bingo = false;
        break;
      }
      if (slen < s[i]) {
        bingo = false;
        break;
      }
      if (second[s[i] - 1] != (c[i] + '0')) {
        bingo = false;
        break;
      }
    }
    if (bingo) {
      bingoNum = min(bingoNum, atoll(second.c_str()));
    }
  }
  if (bingoNum == 1000) {
    cout << -1 << endl;
  } else {
    cout << bingoNum << endl;
  }
  return 0;
}
