#include <bits/stdc++.h>
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
using namespace std;
int a[4];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  memset(a, -1, sizeof(a));
  int s[m + 2], c[m + 2];
  for (size_t i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    s[i]--;
    if (a[s[i]] != -1 && a[s[i]] != c[i]) {
      cout << -1;
      return 0;
    } else {
      a[s[i]] = c[i];
    }
  }
  if (n == 1) {
    if (a[0] == -1) {
      cout << 0;
    } else {
      cout << a[0];
    }
  } else {
    if (a[0] == 0) {
      cout << -1;
      return 0;
    } else {
      for (size_t i = 0; i < n; i++) {
        if (a[i] == -1) {
          cout << 0;
        } else {
          cout << a[i];
        }
      }
    }
  }
  return 0;
}
