#include <bits/stdc++.h>
using namespace std;
int N, M, s, c;
bool exist = true;
vector<int> s_c(4, -1);
int main() {
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> s >> c;
    if (s_c[s] >= 0 && s_c[s] != c) {
      exist = false;
      break;
    }
    if (s == 1 && c == 0) {
      if (N == 1)
        s_c[s] = 0;
      else {
        exist = false;
        break;
      }
    }
    s_c[s] = c;
  }
  if (exist) {
    for (int i = 1; i <= N; i++) {
      if (s_c[i] < 0) {
        if (i == 1) {
          if (i == N)
            cout << 0;
          else
            cout << 1 << endl;
        } else
          cout << 0;
      } else
        cout << s_c[i];
    }
    cout << endl;
  } else
    cout << -1 << endl;
  return 0;
}
