#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  map<int, int> mp;
  for (long long i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    if (a == 1 && b == 0) {
      cout << -1 << endl;
      return 0;
    } else {
      if (mp.count(a) == 0) {
        mp[a] = b;
      } else {
        if (mp[a] != b) {
          cout << -1 << endl;
          return 0;
        } else {
          mp[a] = b;
        }
      }
    }
  }
  if (mp.size() == 1) {
    cout << mp[0] << endl;
  } else {
    int y = 0;
    int temp = 1;
    for (auto itr : mp) {
      temp = 1;
      for (long long i = 0; i < 3 - itr.first; i++) {
        temp *= 10;
      }
      y += temp * itr.second;
    }
    cout << y << endl;
  }
  return 0;
}
