#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
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;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
bool compare(pair<long long, long long> a, pair<long long, long long> b) {
  if (a.first != b.first) {
    return a.first < b.first;
  } else {
    return a.second < b.second;
  }
}
bool In_map(long long y, long long x, long long h, long long w) {
  if (y < 0 || x < 0 || y >= h || x >= w) {
    return 0;
  } else {
    return 1;
  }
}
const vector<long long> dx{1, 0, -1, 0};
const vector<long long> dy{0, 1, 0, -1};
int main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> s(M);
  vector<long long> c(M);
  vector<long long> m(N, -1);
  for (int i = 0; i < (M); i++) {
    cin >> s[i] >> c[i];
    s[i]--;
    if (m[s[i]] != -1 && m[s[i]] != c[i] || (s[i] == 0 && c[i] == 0)) {
      cout << -1 << endl;
      return 0;
    }
    m[s[i]] = c[i];
  }
  for (int i = 0; i < (N); i++) {
    if (m[i] == -1 && i == 0 && N == 1) {
      cout << 0;
    } else if (m[i] == -1 && i == 0) {
      cout << 1;
    } else if (m[i] == -1) {
      cout << 0;
    } else {
      cout << m[i];
    }
  }
  cout << endl;
  return 0;
}
