#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> ds(N, -1);
  bool isExist = true;
  for (int i = 0; i < (int)(M); i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (ds[s] == -1) {
      ds[s] = c;
    } else {
      if (ds[s] != c) {
        isExist = false;
      }
    }
  }
  if (!isExist) {
    cout << -1 << endl;
    return 0;
  }
  int sum = 0;
  for (int i = 0; i < (int)(N); i++) {
    if (ds[i] == -1) {
      sum = sum * 10;
    } else {
      sum = sum * 10 + ds[i];
    }
  }
  if (2 <= N) {
    if ((int)to_string(sum).size() != N) {
      if (ds[0] == -1) {
        sum += 100;
      } else {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  cout << sum << endl;
  return 0;
}
