#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int x, y;
  int arr[3];
  for (int i = 0; i < 3; i++) {
    arr[i] = 0;
  }
  for (int i = 1; i <= m; i++) {
    cin >> x >> y;
    arr[x - 1] = y;
  }
  if (arr[2] != 0) {
    for (int i = 0; i < 3; i++) {
      cout << arr[i];
    }
  } else if (arr[2] == 0) {
    cout << "-1" << endl;
  }
}
