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