#include <bits/stdc++.h>
using namespace std;
int digit(int x) {
  if (x == 0) {
    return 1;
  }
  int ret = 0;
  while (x > 0) {
    ++ret;
    x /= 10;
  }
  return ret;
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> v(N, -1);
  bool ok = true;
  for (int i = 0; i < M; ++i) {
    int s, c;
    cin >> s >> c;
    --s;
    if (v[s] >= 0 && v[s] != c) {
      ok = false;
    }
    v[s] = c;
  }
  if (!ok) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < N; ++i) {
    if (v[i] < 0) {
      v[i] = 0;
    }
  }
  for (int i = 0; i < 1000; ++i) {
    if (digit(i) != N) {
      continue;
    }
    ok = true;
    int x = i;
    for (int j = N - 1; j >= 0; --j) {
      if (x % 10 != v[j]) {
        ok = false;
      }
      x /= 10;
    }
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
