#include <bits/stdc++.h>
using namespace std;
const int mxn = 4;
int main() {
  int n, m;
  cin >> n >> m;
  int ar[mxn] = {0, 1, 0, 0};
  int arr[mxn] = {0, 0, 0, 0};
  if (n < 2 && m == 0) {
    cout << 0;
    return 0;
  } else {
    ar[1] = 0;
  }
  int count = 0;
  while (m--) {
    int s, c;
    cin >> s >> c;
    if (n < 2) {
      if (arr[s] == 0) {
        ar[s] = c;
      }
    } else {
      if (arr[s] == 0) {
        ar[s] = c;
        arr[s]++;
      } else {
        if (ar[s] != c) {
          count++;
        }
      }
    }
  }
  if (count != 0) {
    cout << -1;
    return 0;
  }
  if (ar[1] == 0) {
    cout << -1;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    cout << ar[i];
  }
  return 0;
}
