#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const vi d8x = {1, 0, -1, 0, 1, -1, -1, 1};
const vi d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vi d4x = {1, 0, -1, 0};
const vi d4y = {0, 1, 0, -1};
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> sc(M);
  for (int i = 0; i < (int)(M); i++) cin >> sc[i].first >> sc[i].second;
  string n;
  bool can = true;
  for (int i = 0; i < (int)(N); i++) n.push_back('0');
  sort(sc.begin(), sc.end());
  for (int i = 0; i < (int)(M); i++) {
    if (N != 1 && sc[i].first == 1 && sc[i].second == 0) {
      can = false;
      break;
    }
    if (i < M - 1 && sc[i].first == sc[i + 1].first &&
        sc[i].second != sc[i + 1].second) {
      can = false;
      break;
    }
    char num = '0' + sc[i].second;
    n[(sc[i].first) - 1] = num;
  }
  if (n[0] == '0') n[0] = '1';
  if (can) {
    cout << n << endl;
  } else {
    cout << -1 << endl;
  }
}
