#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m, a, b;
  bool flag = true;
  cin >> n >> m;
  int *arr = new int[n];
  for (int i = 0; i < n; i++) {
    arr[i] = 0;
  }
  for (int i = 0; i < (int)(m); ++i) {
    cin >> a >> b;
    if (arr[a - 1] == 0) {
      arr[a - 1] = b;
    } else if (arr[a - 1] != b) {
      flag = false;
      break;
    } else {
      arr[a - 1] = b;
    }
  }
  if (arr[0] == 0 && n > 1) {
    flag = false;
  }
  if (flag) {
    for (int i = 0; i < (int)(n); ++i) {
      cout << arr[i];
    }
  } else {
    cout << "-1";
  }
  return 0;
}
