#include <bits/stdc++.h>
using namespace std;
long long calcNumOfCombination(long long n, long long r) {
  long long num = 1;
  for (long long i = 1; i <= r; i++) {
    num = num * (n - i + 1) / i;
  }
  return num;
}
int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }
int findSumDigits(int s) {
  int num = 0;
  int temp = 0;
  while (s) {
    temp = s % 10;
    num += temp;
    s = s / 10;
  }
  return num;
}
int main() {
  int n, m;
  cin >> n >> m;
  int ans[n];
  int count[n];
  for (int k = 0; k < (int)(n); k++) {
    ans[k] = 0;
    count[k] = 0;
  }
  int suf = 0;
  int ele = 0;
  for (int i = 0; i < (int)(m); i++) {
    cin >> suf >> ele;
    if (suf == 1 && ele == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (count[suf - 1] == 0) {
      ans[suf - 1] = ele;
    } else {
      if (ans[suf - 1] != ele) {
        cout << -1 << endl;
        return 0;
      }
    }
    count[suf - 1]++;
  }
  if (count[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < (int)(n); i++) {
    cout << ans[i];
  }
  return 0;
}
