#include <bits/stdc++.h>
using namespace std;
int pow(int a, int b) {
  int x = 1;
  for (int i = 0; i < b; ++i) {
    x *= a;
  }
  return x;
}
int main() {
  int N, M, ans = 0, s, c;
  cin >> N >> M;
  map<int, int> sc;
  for (int i = 0; i < M; ++i) {
    cin >> s >> c;
    if (sc.count(s)) {
      if (sc[s] != c) {
        ans = -1;
        break;
      }
    }
    sc[s] = c;
  }
  if (!(sc.count(1))) {
    if (ans != -1) ans += pow(10, N - 1);
  } else {
    if (sc[1] == 0) ans = -1;
  }
  if (ans != -1) {
    for (auto itr = sc.begin(); itr != sc.end(); ++itr) {
      ans += pow(10, N - itr->first) * itr->second;
    }
  }
  cout << ans << endl;
}
