#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, m;
  cin >> n >> m;
  vector<long long> number(n, -1);
  for (int i = 0; i < m; ++i) {
    int pos, digit;
    cin >> pos >> digit;
    pos--;
    if (number[pos] != -1 && number[pos] != digit) {
      cout << -1 << "\n";
      return 0;
    }
    number[pos] = digit;
  }
  if (number[0] == -1) {
    if (n == 1)
      number[0] = 0;
    else
      number[0] = 1;
  }
  if (number[1] == -1) number[1] = 0;
  if (number[2] == -1) number[2] = 0;
  if (number[0] == 0 && n > 1) {
    cout << -1 << "\n";
    return 0;
  }
  cout << number[0] << number[1] << number[2] << "\n";
  cout << "\n";
  return 0;
}
