#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> nums;
  bool flg = true;
  int result = 0;
  for (int i = 0; i < M; ++i) {
    pair<int, int> sc;
    cin >> sc.first >> sc.second;
    if (sc.first > N) {
      flg = false;
      break;
    }
    if (N != 1 && sc.first == 1 && sc.second == 0) {
      flg = false;
      break;
    }
    bool flg2 = false;
    for (int j = 0; j < i; ++j) {
      pair<int, int> pre_sc = nums.at(j);
      if (pre_sc.first == sc.first && pre_sc.second != sc.second) {
        flg = false;
        break;
      } else if (pre_sc.first == sc.first && pre_sc.second == sc.second) {
        flg2 = true;
        break;
      }
    }
    if (flg2) {
      continue;
    }
    nums.push_back(sc);
    if (!flg) {
      break;
    }
    result += sc.second * pow(10, N - sc.first);
  }
  if (flg) {
    cout << result << endl;
  } else {
    cout << -1 << endl;
  }
}
