#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
int main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> ans(n, 0);
  bool no = false;
  for (long long i = 0; i < m; i++) {
    long long s, c;
    cin >> s >> c;
    s--;
    if (ans[s] == 0 || ans[s] == c)
      ans[s] = c;
    else {
      no = true;
    }
  }
  if (no) {
    cout << -1 << endl;
    return 0;
  }
  if (n > 1 && ans[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (long long i = 0; i < n; i++) {
    cout << ans[i];
  }
  cout << endl;
  return 0;
}
