#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
const int MOD = 1000000007;
template <class T>
void print(const T& t) {
  cout << t << endl;
}
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;
}
int main() {
  ll n, m;
  cin >> n >> m;
  bool z = false;
  string t(n, 0);
  t[0] = '1';
  if (n == 1) t = "0";
  vi s(m);
  vi c(m);
  for (ll i = 0; i < (ll)(m); i++) {
    cin >> s[i] >> c[i];
    if (s[i] == 1 && c[i] == 0 && n != 1) {
      z = true;
    }
  }
  for (ll i = 0; i < m; i++) {
    for (ll j = i + 1; j < m; j++) {
      if (s[i] == s[j] && c[i] != c[j]) {
        z = true;
      }
    }
  }
  if (z) {
    print(-1);
  } else {
    for (ll i = 0; i < (ll)(m); i++) {
      t[s[i] - 1] = c[i];
    }
    print(t);
  }
}
