#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, m;
  cin >> n >> m;
  vector<long long> a(n, 10);
  bool flag = false;
  for (long long i = 0; i < m; i++) {
    long long idx, val;
    cin >> idx >> val;
    --idx;
    if (a[idx] == 10 || a[idx] == val)
      a[idx] = val;
    else {
      cout << -1 << endl;
      flag = true;
    }
  }
  if (flag) return;
  for (long long j = 0; j < n; j++)
    if (a[j] == 10) a[j] = 0;
  long long ans = 0, i = 0;
  while (i < n && a[i] == 0) i++;
  if (i != 0) {
    cout << -1 << endl;
    return;
  }
  for (; i < n; i++) ans = ans * 10 + a[i];
  cout << ans << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  while (t--) solve();
  return 0;
}
