#include <bits/stdc++.h>
using namespace std;
signed main(void) {
  long long n, m, ans, w, p, q;
  ans = 0;
  cin >> n >> m;
  long long a[n];
  for (long long i = 0; i < n; i++) a[i] = 0;
  for (long long i = 0; i < m; i++) {
    cin >> p >> q;
    if (n > 1 && p == 1 && q == 0) {
      cout << "-1" << endl;
      return 0;
    } else if (a[p - 1] == 0)
      a[p - 1] = q;
    else if (a[p - 1] != q) {
      cout << "-1" << endl;
      return 0;
    } else
      a[p - 1] = q;
  }
  if (n > 1 && a[0] == 0) {
    cout << "-1" << endl;
    return 0;
  }
  for (long long i = 0; i < n; i++) cout << a[i];
  cout << endl;
}
