#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
int main() {
  int N, M;
  cin >> N >> M;
  vi s(M);
  vi c(M);
  for (int i = 0; i < (M); i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < (M); i++) {
    if ((N == 2 || N == 3) && (s[i] == 1 && c[i] == 0)) {
      cout << "-1" << endl;
      return 0;
    }
    for (int j = 0; j < (M); j++) {
      if (s[i] == s[j] && c[i] != c[j]) {
        cout << "-1" << endl;
        return 0;
      }
    }
  }
  int ans;
  string num = "";
  bool flag = false;
  bool exe = true;
  if (N == 1) {
    for (int i = 0; i < (M); i++) {
      ans = i;
      for (int j = 0; j < (M); j++) {
        if (i == c[j]) {
          break;
          exe = false;
        }
      }
    }
  }
  for (int i = pow(10, N - 1); i < pow(10, N); i++) {
    if (!exe) break;
    num = to_string(i);
    for (int j = 0; j < (M); j++) {
      if (num[s[j] - 1] != (char)c[j]) break;
      if (j == M - 1) {
        flag = true;
        break;
      }
    }
    if (flag) break;
  }
  if (exe)
    cout << num << endl;
  else
    cout << ans << endl;
  return 0;
}
