#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll INF = 1LL << 60;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> arr(N, -1);
  for (ll i = (0); (i) < (M); i++) {
    int digit;
    cin >> digit, --digit;
    int value;
    cin >> value;
    if (arr[digit] != -1) {
      if (value != arr[digit]) {
        cout << -1 << endl;
        return 0;
      }
    }
    if (N > 1 && digit == 0 && value == 0) {
      cout << -1 << endl;
      return 0;
    }
    arr[digit] = value;
  }
  if (arr[0] != -1)
    cout << arr[0];
  else
    cout << 1;
  for (ll i = (1); (i) < (N); i++) {
    if (arr[i] != -1) {
      cout << arr[i];
    } else {
      cout << 0;
    }
  }
  cout << endl;
}
