#include <bits/stdc++.h>
using namespace std;
inline int rint() {
  int x;
  scanf("%d", &x);
  return x;
}
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long eea(long long a, long long b, long long &x, long long &y) {
  if (!b) {
    x = 1, y = 0;
    return a;
  }
  long long x1, y1;
  long long d = eea(b, a % b, x1, y1);
  x = y1;
  y = x1 - (long long)(a / b) * y1;
  return d;
}
long long gcd(long long a, long long b) {
  long long x;
  long long y;
  return eea(a, b, x, y);
}
void solve();
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  return 0;
}
void solve() {
  int n = rint();
  int m = rint();
  int ans[n];
  for (int i = 0; i < (n); ++i) ans[i] = -1;
  for (int i = 0; i < (m); ++i) {
    int p = rint();
    int v = rint();
    if (p == 1 && v == 0 && n != 1) {
      cout << "-1";
      return;
    }
    if (ans[p - 1] == -1) {
      ans[p - 1] = v;
      continue;
    }
    if (ans[p - 1] != v) {
      cout << "-1";
      return;
    }
  }
  for (int i = 0; i < (n); ++i) {
    if (ans[i] == -1)
      cout << 0;
    else
      cout << ans[i];
  }
}
