#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 << 0 << endl;
    return 0;
  }
  long long len = 0;
  if (N == 1) len = 9;
  if (N == 2) len = 99;
  if (N == 3) len = 999;
  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;
    if (slen == N) {
      for (long long j = 0; j < M; j++) {
        if (slen < s[j]) {
          bingo = false;
          break;
        }
        if (second[s[j] - 1] != to_string(c[j])[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;
}
