#include <bits/stdc++.h>
using namespace std;
int i, j, k, count1 = 0, count2 = 0;
int gcd(int, int);
void ABC157();
void ABC158();
void ABC161();
void ABC162();
void ABC163();
void ABC164();
int main() { ABC157(); }
void ABC157() {
  int s, c, ans = 1, n, m;
  cin >> n >> m;
  vector<int> vec(n, 10);
  for (i = 0; i < m; i++) {
    cin >> s >> c;
    if (vec[s - 1] == 10) {
      vec[s - 1] = c;
    } else if (vec[s - 1] != c) {
      ans = 0;
      break;
    }
  }
  if (ans == 1 && n >= 2 && vec[0] != 0) {
    for (i = 0; i < n; i++) {
      if (vec[i] == 10 && i == 0)
        cout << 1;
      else if (vec[i] == 10)
        cout << 0;
      else
        cout << vec[i];
    }
    cout << endl;
  } else {
    cout << -1 << endl;
  }
}
