#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  vector<int> arr(n, 0);
  int ans = 0;
  for (int i = 0; i < m; i++) {
    int y, x;
    cin >> y >> x;
    if (i == 0 && x == 0) {
      ans = -1;
    }
    if (arr[y - 1] == 0 || arr[y - 1] == x) {
      arr[y - 1] = x;
    } else {
      ans = -1;
    }
  }
  if (ans == -1) {
    cout << -1;
  } else {
    for (int i : arr) {
      cout << i;
    }
  }
  return 0;
}
