#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
void solve() {
  int N, M;
  cin >> N >> M;
  vector<int> rules(N + 1, -1);
  bool failCheck = false;
  for (int _ = 0, __len = (M); _ < __len; ++_) {
    int s, c;
    cin >> s >> c;
    if (s == 1 && c == 0) {
      failCheck = true;
    }
    if (rules[s] == -1) {
      rules[s] = c;
      continue;
    }
    if (rules[s] != c) {
      cout << -1 << endl;
      return;
    }
  }
  if (failCheck) {
    if (rules[1] == 0 && N == 1)
      cout << 0 << endl;
    else
      cout << -1 << endl;
    return;
  }
  for (int i = 0, i_len = (N); i < i_len; ++i) {
    auto mini = (i == 0) ? 1 : 0;
    cout << ((rules[i + 1] != -1) ? rules[i + 1] : mini);
  }
  cout << endl;
}
int main() {
  solve();
  return 0;
}
