#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const long long INF = 1LL << 60;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s_cnt(n);
  vector<int> v_c(n);
  for (int i = 0; i < n; i++) v_c[i] = 0;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    s_cnt[s] += 1;
    if (s_cnt[s] == 1) {
      v_c[s] = c;
    } else {
      if (v_c[s] != c) {
        cout << "-1" << endl;
        return 0;
      }
    }
    if (n != 1 && s == 0 && c == 0) {
      cout << "-1" << endl;
      return 0;
    }
  }
  if (n == 1) {
    for (int i = 0; i <= 9; i++) {
      ostringstream oss;
      oss << i;
      string s = oss.str();
      bool temp = true;
      for (int j = 0; j < s.size(); j++) {
        if (s[j] != to_string(v_c[j])[0]) temp = false;
      }
      if (temp) {
        cout << i << endl;
        return 0;
      }
    }
  }
  if (n == 2) {
    for (int i = 10; i <= 99; i++) {
      ostringstream oss;
      oss << i;
      string s = oss.str();
      bool temp = true;
      for (int j = 0; j < s.size(); j++) {
        if (s[j] != to_string(v_c[j])[0]) temp = false;
      }
      if (temp) {
        cout << i << endl;
        return 0;
      }
    }
  }
  if (n == 3) {
    for (int i = 100; i <= 999; i++) {
      string s = to_string(i);
      bool temp = true;
      for (int j = 0; j < s.size(); j++) {
        if (s[j] != to_string(v_c[j])[0]) {
          temp = false;
        }
      }
      if (temp == true) {
        cout << i << endl;
        return 0;
      }
    }
  }
  cout << "-1" << endl;
  return 0;
}
