#include <bits/stdc++.h>
using namespace std;
int main() {
  long long i, j;
  long long n, m;
  cin >> n >> m;
  long long arr[4] = {0, 0, 0, 0};
  while (m--) {
    long long pos, no;
    cin >> pos >> no;
    if (arr[pos] == 0 || arr[pos] == no)
      arr[pos] = no;
    else {
      cout << "-1";
      return 0;
    }
  }
  string s = "";
  for (i = 1; i < 4; i++) s += to_string(arr[i]);
  long long made = stoi(s);
  s = to_string(made);
  if (s != "0")
    cout << s;
  else
    cout << "-1";
}
