#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  if (M != 0) {
    for (int i = 0; i < M; i++) {
      cin >> s.at(i) >> c.at(i);
    }
    int digit = 0;
    for (int i = 0; i < M; i++) {
      digit = (digit <= s.at(i)) ? s.at(i) : digit;
    }
    vector<int> dig(digit);
    for (int i = 0; i < digit; i++) {
      dig.at(i) = -1;
    }
    int cnt = 0;
    bool flag = false;
    for (int i = 0; i < M; i++) {
      if ((dig.at(digit - s.at(i)) != c.at(i)) &&
          (dig.at(digit - s.at(i)) != -1))
        flag = true;
      cnt -= ((cnt / (int)(pow(10, (digit - s.at(i))))) % 10) *
             (pow(10, (digit - s.at(i))));
      cnt += pow(10, (digit - s.at(i))) * c.at(i);
      dig.at(digit - s.at(i)) = c.at(i);
    }
    int min;
    if (N == 1) {
      min = 0;
    } else {
      min = pow(10, N - 1);
    }
    int max = pow(10, N);
    if (min <= cnt && cnt < max) {
      cnt = cnt;
    } else {
      cnt = -1;
    }
    if (flag) cnt = -1;
    cout << cnt;
  } else {
    int cnt = 0;
    cnt = pow(10, N - 1);
    cout << cnt;
  }
}
