#include <bits/stdc++.h>
using namespace std;
long long arr[100001];
bool vis[100001];
long long lvl[100001];
long long powM(long long a, long long b, long long m) {
  a %= m;
  long long ans = 1;
  while (b > 0) {
    if (b & 1) ans = ans * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return ans;
}
long long pow(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = ans * a;
    a = a * a;
    b >>= 1;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, m;
  cin >> n >> m;
  long long d = m;
  vector<long long> dig(n + 1, -1);
  while (d--) {
    long long a, b;
    cin >> a >> b;
    if (dig[a] == -1)
      dig[a] = b;
    else {
      if (b != dig[a]) {
        cout << -1 << "\n";
        return 0;
      }
    }
  }
  if (m == 0 && n == 1) {
    cout << 0 << "\n";
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    if (dig[i] == -1) {
      if (i == 1)
        dig[i] = 1;
      else
        dig[i] = 0;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (dig[1] == 0) {
      cout << -1 << "\n";
      return 0;
    }
    cout << dig[i];
  }
  return 0;
}
