#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a[n];
  memset(a, -1, sizeof(a));
  int r = 1;
  while (m--) {
    int s, c;
    cin >> s >> c;
    if (a[s - 1] == -1 || a[s - 1] == c)
      a[s - 1] = c;
    else {
      r = 0;
    }
  }
  if (r == 0) {
    cout << "-1" << endl;
    return 0;
  }
  int count = 0;
  int ans = -1;
  int flag = 1;
  for (int i = 0; i < n; i++) {
    if (a[i] == 0) {
      if (flag) {
        cout << "-1" << endl;
        break;
      }
    } else {
      flag = 0;
    }
  }
  string myans = "";
  if (flag == 0) {
    for (int i = 0; i < n; i++) {
      myans += to_string(a[i]);
    }
    cout << myans << endl;
  }
  return 0;
}
