#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  map<int, int> map;
  bool flag = true;
  bool zeroflag = true;
  for (int i = 0; i < (M); ++i) {
    int key, value;
    cin >> key >> value;
    if (N == 1 && key == 1 && value == 0) {
      zeroflag = false;
    } else if (key == 1 && value == 0) {
      flag = false;
    }
    try {
      if (map.at(key) != value) {
        flag = false;
      }
    } catch (std::out_of_range& e) {
      map.emplace(key, value);
    }
  }
  if (!zeroflag) {
    cout << 0;
    return 0;
  } else if (!flag) {
    cout << -1;
    return 0;
  } else {
    for (int i = 1; i <= N; ++i) {
      try {
        if (map.at(i)) {
          cout << map[i];
        }
      } catch (std::out_of_range& e) {
        if (i == 1) {
          cout << 1;
        } else {
          cout << 0;
        }
      }
    }
  }
  return 0;
}
