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