#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, bool>> num(N);
  for (int i = 0; i < N; ++i) {
    num[i].second = true;
  }
  vector<pair<int, int>> sc(M);
  for (int i = 0; i < M; ++i) {
    cin >> sc[i].first >> sc[i].second;
    if (num[sc[i].first - 1].second == true) {
      num[sc[i].first - 1].first = sc[i].second;
      num[sc[i].first - 1].second = false;
    } else {
      if (sc[i].second != num[sc[i].first - 1].first) {
        puts("-1");
        return 0;
      }
    }
  }
  if (num[0].first == 0) {
    puts("-1");
  } else {
    for (int i = 0; i < N; ++i) {
      cout << num[i].first;
    }
    cout << endl;
  }
  return 0;
}
