#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> data(N, 10);
  int ans = 0;
  if (M == 0) {
    ans += pow(10, N - 1);
    if (ans == 1) {
      cout << 0 << endl;
      return 0;
    }
  } else {
    for (int i = 0; i < M; i++) {
      int keta, num;
      cin >> keta >> num;
      keta--;
      if (keta == 0) {
        if (data[0] == 0 && num != 0)
          data[keta] = num;
        else if (data[num] != 0 && num == 0)
          continue;
        else
          data[keta] = min(data[keta], num);
      } else {
        data[keta] = min(data[keta], num);
      }
    }
    for (int i = 0; i < N; i++) {
      if (data[i] == 10) {
        data[i] = 0;
      }
      if (i == 0 && data[i] == 0 && N != 1) {
        cout << -1 << endl;
        return 0;
      }
      ans += data[i] * pow(10, N - i - 1);
    }
  }
  cout << ans << endl;
}
