#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  return b ? gcd(b, a % b) : a;
}
long long int lcm(long long int a, long long int b) {
  return a / gcd(a, b) * b;
}
long long int input() {
  long long int a;
  cin >> a;
  return a;
}
vector<long long int> sub(vector<bool> fin, long long int n) {
  vector<long long int> ret;
  for (int i = 0; i < n; i++) {
    if (fin.at(i)) continue;
    vector<bool> cp = fin;
    cp.at(i) = true;
    vector<long long int> result = sub(cp, n);
    ret.insert(ret.end(), result.begin(), result.end());
  }
  return ret;
}
long long int pow_kai(long long int a, long long int n) {
  long long int x = 1;
  while (n > 0) {
    if (n & 1) x = x * a;
    a = a * a;
    n >>= 1;
  }
  return x;
}
int main() {
  long long int n, m;
  cin >> n >> m;
  vector<char> ans(n, '0');
  vector<bool> check(n, true);
  for (int i = 0; i < m; i++) {
    long long int s;
    char c;
    cin >> s >> c;
    check.at(s - 1) = false;
    if ((ans.at(s - 1) != '0' && ans.at(s - 1) != c) || (s == 1 && c == '0')) {
      cout << -1 << endl;
      return 0;
    }
    ans.at(s - 1) = c;
  }
  char f = false;
  string res = "";
  for (int i = 0; i < n; i++)
    if (f || ans.at(i) != '0') {
      res.push_back(ans.at(i));
    } else {
      res.push_back('1');
      f = true;
    }
  if (res == "") {
    reverse(check.begin(), check.end());
    long long int q = 0;
    for (int i = 0; i < n; i++) {
      if (check.at(i)) {
        q += pow(10, i);
        cout << q << endl;
        break;
      }
    }
    if (!q) cout << -1 << endl;
  } else
    cout << res << endl;
}
