#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N, M;
  cin >> N >> M;
  int data[N];
  for (int i = (0); i < (N); i++) data[i] = -1;
  for (int i = (0); i < (M); i++) {
    int A, B;
    cin >> A;
    cin >> B;
    if (data[A - 1] != B && data[A - 1] != -1) {
      cout << -1 << endl;
      return 0;
    }
    data[A - 1] = B;
  }
  bool boolean = false;
  for (int i = (0); i < (N); i++) {
    if (boolean == false && (data[i] != -1 || data != 0)) {
      boolean = true;
      int sum = 0;
      for (int j = (i); j < (N); j++) {
        if (data[j] == -1) data[j] = 0;
        sum += data[j];
      }
      if (sum == 0) {
        cout << -1 << endl;
        return 0;
      }
      cout << data[i];
    } else if (boolean == false) {
      continue;
    } else {
      cout << data[i];
    }
  }
  cout << endl;
}
