#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
int INF = 1 << 30;
long long INFL = 1LL << 60;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (long long i = 0; i < (M); i++) {
    cin >> s[i] >> c[i];
  }
  vector<int> num(N + 1, -1);
  bool hantei = false;
  for (long long i = 0; i < (M); i++) {
    if (num[s[i]] == -1) {
      num[s[i]] = c[i];
    } else if (num[s[i]] == c[i])
      num[s[i]] = c[i];
    else {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 1; i <= N; i++) {
    if (num[i] == -1) num[i] = 0;
  }
  if (N == 1) cout << num[1] << endl;
  if (num[1] == 0 && N > 1) {
    cout << -1 << endl;
  } else {
    for (int i = 1; i <= N; i++) cout << num[i];
    cout << endl;
  }
}
