#include <bits/stdc++.h>
using namespace std;
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 || (N > 1 && v[0] == 0)) {
    cout << -1 << endl;
    return 0;
  }
  if (N == 1 && v[0] == 0) {
    cout << 0 << endl;
    return 0;
  }
  if (M == 0) {
    int ans = 1;
    for (int i = 0; i < N - 1; ++i) {
      ans *= 10;
    }
    cout << ans << endl;
    return 0;
  }
  int ans = 0;
  ok = false;
  for (int i = 0; i < N; ++i) {
    if (!ok && v[i] < 0) {
      continue;
    }
    if (!ok && v[i] == 0) {
      ans += 10;
      ok = true;
      continue;
    }
    ok = true;
    if (v[i] < 0) {
      v[i] = 0;
    }
    ans *= 10;
    ans += v[i];
  }
  cout << (ok ? ans : -1) << endl;
  return 0;
}
