#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e9) + 1;
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;
}
int main() {
  int n, m;
  scanf("%d", &n);
  scanf("%d", &m);
  int s[m];
  int c[m];
  for (int i; i < m; ++i) {
    cin >> s[i] >> c[i];
  }
  int d[n + 1];
  for (int i = 1; i <= (int)(n); i++) d[i] = -1;
  int ans = -1;
  int check = 0;
  for (int i = 0; i < (int)(m); i++) {
    if (s[i] > n || s[i] == 0) {
      check = 1;
      break;
    }
    if (d[s[i]] >= 0 && d[s[i]] != c[i]) {
      check = 1;
      break;
    }
    d[s[i]] = c[i];
  }
  for (int i = 1; i <= (int)(n); i++) {
    if (d[i] < 0) d[i] = 0;
  }
  if (check == 1 || d[1] == 0) {
    cout << -1 << endl;
  } else {
    for (int i = 1; i <= (int)(n); i++) cout << d[i];
    cout << endl;
  }
  return 0;
}
