#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a % b == 0) return b;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
  long long c = gcd(a, b);
  return ((a / c) * (b / c) * c);
}
const long long INF = long long(1e16) + long long(7);
const long long MOD = 1000000007LL;
int main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> s(M);
  vector<char> c(M);
  string ans;
  for (long long i = long long(0); i < long long(N); ++i) ans = ans + 'x';
  for (long long i = long long(0); i < long long(M); ++i) {
    cin >> s[i] >> c[i];
    if (ans[s[i] - 1] == c[i] || ans[s[i] - 1] == 'x') {
      ans[s[i] - 1] = c[i];
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (N == 1 && ans[0] == 'x') {
    cout << 0 << endl;
    return 0;
  }
  if (ans[0] == 'x') ans[0] = '1';
  if (ans[0] == '0') {
    cout << -1 << endl;
    return 0;
  }
  for (long long i = long long(0); i < long long(N); ++i) {
    if (ans[i] == 'x') ans[i] = '0';
  }
  cout << ans << endl;
}
