#include <bits/stdc++.h>
using namespace std;
int n, m;
map<int, int> ma;
vector<int> vec;
unordered_set<int> se;
int calcketa(int num) {
  int keta = 1;
  while (num / 10 != 0) {
    keta++;
    num /= 10;
  }
  return keta;
}
bool confirm(int a) {
  for (int i = 0; i < (n); i++) {
    int ketan = a % 10;
    a /= 10;
    if (ketan != vec[n - i - 1]) {
      return false;
    }
  }
  return true;
}
int main() {
  cin >> n >> m;
  vec.resize(n);
  for (int i = 0; i < (m); i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (se.count(s) != 0 && ma[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    ma[s] = c;
    se.insert(s);
    vec[s] = c;
  }
  int ans = 0;
  for (int i = 0; i < (n); i++) {
    int keta = n - i - 1;
    ans += ma[i] * pow(10, keta);
  }
  if (ans == 0 && n == 1) {
    cout << ans << endl;
    return 0;
  }
  if (calcketa(ans) != n || !confirm(ans)) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
}
