#include <bits/stdc++.h>
using namespace std;
int a, b, c, i, j, k;
long long ans = 0LL;
int main() {
  int n, m, s, c;
  scanf("%d%d", &n, &m);
  vector<int> vec(n, -1);
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &s, &c);
    s--;
    if (s >= m || s < 0) {
      cout << "-1" << endl;
      return 0;
    }
    if (vec[s] != -1 && vec[s] != c) {
      cout << "-1" << endl;
      return 0;
    }
    if (s == 0 && c == 0) {
      cout << "-1" << endl;
      return 0;
    }
    vec[s] = c;
  }
  if (n == 1) {
    if (vec[0] == -1) {
      cout << 0 << endl;
      return 0;
    } else {
      cout << vec[0] << endl;
    }
  } else {
    if (vec[0] == -1) {
      cout << -1 << endl;
      return 0;
    }
    for (int i = 0; i < n; ++i) {
      if (vec[i] == -1) {
        cout << 0;
      } else {
        cout << vec[i];
      }
    }
  }
  cout << endl;
  return 0;
}
