#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;
  }
  for (long long i = 0; i < 1000; i++) {
    string a = to_string(i);
    long long len = a.length();
    if (len != N) {
      continue;
    }
    bool ok = true;
    for (long long j = 0; j < M; j++) {
      if (c[j] + '0' != (a[s[j] - 1])) {
        ok = false;
      }
    }
    if (ok) {
      cout << a << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
