#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const ll INF = 1LL << 60;
int main() {
  int n, m;
  cin >> n >> m;
  int now[3];
  for (ll i = 0; i < (ll)(3); i++) now[i] = -1;
  for (ll i = 0; i < (ll)(m); i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (c == 0 && s == 0 && n != 1) {
      cout << -1 << endl;
      return 0;
    }
    if (now[s] == -1 || now[s] == c)
      now[s] = c;
    else {
      cout << -1 << endl;
      return 0;
    }
  }
  for (ll i = 0; i < (ll)(3); i++) {
    if (now[0] == -1) {
      cout << -1 << endl;
      break;
    }
    if (now[i] == -1)
      cout << 0;
    else
      cout << now[i];
  }
  return 0;
}
