#include <bits/stdc++.h>
using namespace std;
using ipair = pair<int, int>;
long long INF = 1e16 + 7;
bool operator>(const ipair a, const ipair b) { return a.first > b.first; }
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> num(N);
  num[0] = 1;
  set<int> keta;
  for (int i = 0; i < (M); ++i) {
    int s, c;
    cin >> s >> c;
    s--;
    if (keta.count(s) != 0 && num[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    num[s] = c;
    keta.insert(s);
  }
  int tmp = 0;
  for (int i = 0; i < (N); ++i) tmp += num[i];
  if (tmp == 0 && N != 1) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < (N); ++i) cout << num[i];
  cout << endl;
}
