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