#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> sc;
  for (int i = 0; i < (int)(m); i++) {
    int s, c;
    cin >> s >> c;
    s = n - s + 1;
    if (sc.count(s) != 0 && sc[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    sc[s] = c;
  }
  if (sc.count(n) == 1 && sc[n] == 0) {
    cout << -1 << endl;
    return 0;
  }
  int ans = 0;
  for (int i = n; i > 0; i--) {
    int val = 1;
    if (sc.count(i) != 0) {
      val = sc[i];
    } else {
      if (i == n) {
        val = 1;
      } else {
        val = 0;
      }
    }
    for (int j = 1; j < i; j++) {
      val *= 10;
    }
    ans += val;
  }
  cout << ans << endl;
}
