#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m], c[m];
  int i;
  for (i = 0; i < m; i++) cin >> s[i] >> c[i];
  int arr[n];
  for (i = 0; i < n; i++) arr[i] = -1;
  int temp = 1;
  for (i = 0; i < m; i++) {
    if (arr[s[i] - 1] == -1 || c[i] == arr[s[i] - 1]) {
      arr[s[i] - 1] = c[i];
    } else {
      temp = 0;
      break;
    }
  }
  if (!temp) {
    cout << "-1";
    return 0;
  }
  for (i = 0; i < n; i++) {
    if (arr[i] == -1) arr[i] = 0;
  }
  int no = 0;
  for (i = 0; i < n; i++) no = no * 10 + arr[i];
  if (no <= 0)
    cout << "-1";
  else
    cout << no;
  return 0;
}
