#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  int arr[n];
  for (int i = 0; i < n; i++) {
    arr[i] = 0;
  }
  int s;
  int v;
  for (int i = 0; i < m; i++) {
    cin >> s >> v;
    if (arr[s - 1] == 0)
      arr[s - 1] = v;
    else {
      if (arr[s - 1] != v) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  if (n > 1 && arr[0] == 0)
    cout << -1 << endl;
  else
    cout << arr[0] << arr[1] << arr[2] << endl;
}
