#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int N, M;
  cin >> N >> M;
  int ans[M];
  bool hantei = true;
  for (int i = 0; i < (M); ++i) ans[i] = -1;
  for (int i = 0; i < (M); ++i) {
    int a, b;
    cin >> a >> b;
    if (ans[a - 1] == -1) {
      ans[a - 1] = b;
    } else if (ans[a - 1] != -1 && ans[a - 1] != b) {
      hantei = false;
    }
  }
  if (ans[0] == 0) {
    hantei = false;
  }
  if (hantei) {
    for (int i = 0; i < (M); ++i) {
      if (ans[i] == -1) {
        ans[i] = 0;
      }
      cout << ans[i];
    }
  } else {
    cout << -1;
  }
  return 0;
}
