#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
unsigned GetDigit(unsigned num) {
  if (num == 0) return 1;
  return log10(num) + 1;
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  for (int i = 0; i < M; i++) cin >> s[i] >> c[i];
  bool ok = false;
  vector<bool> ch(N, false);
  vector<int> us(N, -1);
  for (int i = 0; i < M; i++) {
    int t = s[i] - 1;
    if (!ch[i]) {
      ch[t] = true;
      us[t] = c[i];
    } else {
      if (us[t] != c[i]) ok = true;
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int tm = 2 - i;
    if (us[i] == -1) {
      continue;
    } else {
      ans += pow(10, tm) * us[i];
    }
  }
  if (ok)
    cout << -1 << endl;
  else {
    int tmp = GetDigit(ans);
    if (tmp == N) {
      cout << ans << endl;
    } else {
      cout << -1 << endl;
    }
  }
}
