#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, n, m, k, i, j;
  string s;
  cin >> n >> m;
  int arr[3];
  set<int> v;
  memset(arr, 0, sizeof(arr));
  for (i = 0; i < m; i++) {
    cin >> a >> b;
    arr[a - 1] = max(arr[a - 1], b);
    v.insert(a);
  }
  if (find(v.begin(), v.end(), n) != v.end()) {
    for (i = 0; i < n; i++) cout << arr[i];
  } else
    cout << "-1" << endl;
}
