#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ull = unsigned long long;
char toSmall(char c) { return (c + 0x20); }
char toLarge(char c) { return (c - 0x20); }
float myPower(int a, int n) {
  float x = 1;
  while (n > 0) {
    if (n & 1) {
      x *= a;
    }
    a *= a;
    n >>= 1;
  }
  return x;
}
struct Combination {
  const int num = 51e4;
  const int mod = 1e9 + 7;
  vector<ll> fact, inv, finv;
  Combination() : fact(num), inv(num), finv(num) {
    fact[0] = fact[1] = 1;
    inv[1] = 1;
    finv[0] = finv[1] = 1;
    for (int i = 2; i < num; ++i) {
      fact[i] = fact[i - 1] * i % mod;
      inv[i] = mod - inv[mod % i] * (mod / i) % mod;
      finv[i] = finv[i - 1] * inv[i] % mod;
    }
  }
  int nCk(int n, int k) {
    if (n < k) return 0;
    if (n < 0 or k < 0) return 0;
    return fact[n] * (finv[k] * finv[n - k] % mod) % mod;
  }
  int big_nCk(int n, int k) {
    ll res = 1LL;
    for (int i = 0; i < k; i++) {
      res = res * (n - i) % mod;
    }
    res = res * finv[k] % mod;
    return res;
  }
  int nHk(int n, int k) { return nCk(n + k - 1, n - 1); }
};
vector<string> split(const string& src, const char* delim = ",") {
  vector<string> vec;
  string::size_type len = src.length();
  for (string::size_type i = 0, n; i < len; i = n + 1) {
    n = src.find_first_of(delim, i);
    if (n == string::npos) {
      n = len;
    }
    vec.push_back(src.substr(i, n - i));
  }
  return vec;
}
bool check_int(string str) {
  if (all_of(str.cbegin(), str.cend(), [](char ch) { return isdigit(ch); })) {
    return true;
  }
  return false;
}
struct rest {
  string s;
  int p;
  int num;
  bool operator<(const rest& right) const {
    return s == right.s ? p > right.p : s < right.s;
  }
};
ll pow_mod(ll n, ll k, ll p) {
  if (k == 0) {
    return 1;
  }
  ll res = pow_mod(n * n % p, k / 2, p);
  if (k & 1) {
    res = res * n % p;
  }
  return res;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> d(m);
  for (int i = 0; i < m; i++) {
    d[i] = -1;
  }
  bool flag = true;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (d[s - 1] == -1 || d[s - 1] == c) {
      d[s - 1] = c;
    } else {
      flag = false;
    }
  }
  if (flag) {
    if ((n > 1 && d[0] == 0) || d[0] == -1) {
      cout << -1 << endl;
      return 0;
    }
    for (int i = 0; i < m; i++) {
      if (d[i] != -1) {
        cout << d[i];
      } else {
        cout << 0;
      }
    }
    return 0;
  }
  cout << -1 << endl;
  return 0;
}
