#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  int i, j, k;
  cin >> n >> m;
  int num[n];
  for (i = 0; i < n; i++) num[i] = -1;
  int s, c;
  for (i = 0; i < m; i++) {
    cin >> s >> c;
    if (num[s - 1] == -1)
      num[s - 1] = c;
    else {
      if (num[s - 1] != c) {
        cout << "-1" << endl;
        return 0;
      } else if (num[s - 1] == c)
        continue;
    }
  }
  if (num[0] == 0) {
    cout << "-1" << endl;
    return 0;
  }
  int ans = 0;
  int digit = 1;
  for (i = n - 1; i >= 0; i--) {
    if (num[i] == -1) {
      digit *= 10;
      continue;
    }
    ans += num[i] * digit;
    digit *= 10;
  }
  cout << ans << endl;
}
