#include <bits/stdc++.h>
using namespace std;
using ll = long long;
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
ll gcd(ll a, ll b) {
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
ll kaizyou(ll N) {
  ll num = 1;
  for (ll i = 1; i <= N; i++) {
    num *= i;
  }
  return num;
}
int dy[] = {-1, 0, 1, 0};
int dx[] = {0, -1, 0, 1};
ll mod = 1e9 + 7;
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> sc(M);
  for (int i = 0; i < (int)(M); i++) {
    int s, c;
    cin >> s >> c;
    sc[i] = make_pair(s, c);
  }
  vector<int> ans(N);
  for (int i = 0; i < (int)(M); i++) {
    if (sc[i].first == 1 && sc[i].second == 0) {
      cout << "-1" << endl;
      return 0;
    }
    if (ans[sc[i].first - 1] != 0) {
      if (ans[sc[i].first - 1] != sc[i].second) {
        cout << "-1" << endl;
        return 0;
      }
    }
    ans[sc[i].first - 1] = sc[i].second;
  }
  if (ans[0] == 0) {
    ans[0] = 1;
  }
  for (int i = 0; i < (int)(N); i++) {
    cout << ans[i];
  }
  cout << endl;
}
