#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long mypow(long long base, long long exp) {
  long long res = 1;
  while (exp) {
    if (exp & 1) res = (res * base) % mod;
    exp >>= 1, base = (base * base) % mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long mult(long long a, long long b) {
  if (a < 0) {
    a += mod;
  }
  if (b < 0) {
    b += mod;
  }
  return ((a % mod) * (b % mod)) % mod;
}
long long add(long long a, long long b) {
  if (a < 0) {
    a += mod;
  }
  if (b < 0) {
    b += mod;
  }
  return (a % mod + b % mod) % mod;
}
long long sub(long long a, long long b) {
  if (a < 0) {
    a += mod;
  }
  if (b < 0) {
    b += mod;
  }
  return (a % mod + mod - b % mod) % mod;
}
const long long inf = 1e18;
const int nax = 1e5 + 5;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    long long a[3];
    a[0] = a[1] = a[2] = -1;
    long long s, c;
    string res = "";
    bool ok = 1;
    for (long long i = 0; i < m; i++) {
      cin >> s >> c;
      if (a[s - 1] == -1) {
        a[s - 1] = c;
      } else {
        if (c == a[s - 1]) {
          continue;
        } else {
          ok = 0;
        }
      }
    }
    if (n == 1) {
      if (a[0] == -1) {
        cout << 0;
      } else {
        cout << a[0];
      }
    } else {
      if (a[0] == 0) {
        cout << -1;
      } else {
        if (a[0] == -1) {
          a[0] = 1;
        }
        if (a[1] == -1) {
          a[1] = 0;
        }
        if (a[2] == -1) {
          a[2] = 0;
        }
        if (ok) {
          for (long long i = 0; i < n; i++) {
            cout << a[i];
          }
        } else {
          cout << -1;
        }
      }
    }
  }
  return 0;
}
