#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, s, c, can, ans, ketasuu;
  can = 1;
  cin >> n >> m;
  vector<int> vec(n);
  vector<int> flag(n);
  for (int i = 0; i < n; i++) {
    vec.at(i) = 99;
    flag.at(i) = 0;
  }
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    s = s - 1;
    if (s == 0 && c == 0) {
      can = 0;
      break;
    }
    if (flag.at(s) == 1 && vec.at(s) != c) {
      can = 0;
      break;
    }
    vec.at(s) = c;
    flag.at(s) = 1;
  }
  if (can == 0) {
    ans = -1;
    cout << ans;
  } else {
    ans = 0;
    ketasuu = 1;
    for (int i = n - 1; 0 <= i; i--) {
      if (i == 0) {
        if (vec.at(i) < 12) {
          ans = ans + vec.at(i) * ketasuu;
        } else {
          ans = ans + ketasuu;
          if (ketasuu == 1) {
            ans = 0;
          }
        }
      } else {
        if (vec.at(i) < 12) {
          ans = ans + ketasuu * vec.at(i);
        }
      }
      ketasuu = ketasuu * 10;
    }
    cout << ans;
  }
}
