#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const int INF = int(2e9);
const long long LINF = long long(2e9) * long long(2e9);
template <class T, class C>
void chmax(T& a, C b) {
  a > b ?: a = b;
}
template <class T, class C>
void chmin(T& a, C b) {
  a < b ?: a = b;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int i = 0; i < M; i++) cin >> s[i] >> c[i];
  vector<int> ans(N + 1, -1);
  for (int i = 0; i < M; i++) {
    if (ans[s[i]] != -1) {
      if (ans[s[i]] != c[i]) {
        cout << -1 << endl;
        return 0;
      }
    } else {
      ans[s[i]] = c[i];
    }
  }
  for (int i = 1; i < N + 1; i++) {
    if (ans[i] == -1) {
      if (i == 1)
        ans[i] = 1;
      else
        ans[i] = 0;
    }
  }
  string ans_str = "";
  if (N >= 2) {
    if (ans[1] == 0) {
      cout << -1 << endl;
      return 0;
    }
    bool all_zero = true;
    for (int i = 1; i < N + 1; i++) {
      if (ans[i] != 0) {
        all_zero = false;
        break;
      }
    }
    if (all_zero == true) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 1; i < N + 1; i++) {
    ans_str += ans[i] + 0x30;
  }
  cout << ans_str << endl;
  return 0;
}
