#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int i = 0; i < M; ++i) cin >> s[i] >> c[i];
  int one = -100, ten = -100, han = -100;
  for (int i = 0; i < M; ++i) {
    if (s[i] == N - 2) {
      if (han == -100)
        han = c[i];
      else {
        if (han != c[i]) {
          cout << -1 << endl;
          return 0;
        }
      }
    }
    if (s[i] == N - 1) {
      if (ten == -100)
        ten = c[i];
      else {
        if (ten != c[i]) {
          cout << -1 << endl;
          return 0;
        }
      }
    }
    if (s[i] == N) {
      if (one == -100)
        one = c[i];
      else {
        if (one != c[i]) {
          cout << -1 << endl;
          return 0;
        }
      }
    }
  }
  one = max(0, one);
  ten = max(0, ten);
  han = max(0, han);
  if (N == 1) cout << one << endl;
  if (N == 2) cout << ten * 10 + one << endl;
  if (N == 3) cout << han * 100 + ten * 10 + one << endl;
  return 0;
}
