#include <bits/stdc++.h>
using namespace std;
int main(int argc, char **argv) {
  int N, M;
  cin >> N >> M;
  int s[M], c[M];
  for (int i = 0; i < M; ++i) {
    cin >> s[i];
    cin >> c[i];
  }
  for (int i = 0; i < M; ++i) s[i]--;
  int d[3];
  for (int i = 0; i < 3; ++i) d[i] = -1;
  for (int i = 0; i < M; ++i) {
    if (d[s[i]] == -1) {
      d[s[i]] = c[i];
    } else {
      if (d[s[i]] != c[i]) {
        cout << -1;
        return 0;
      }
    }
  }
  if (N == 1) {
    if (d[0] == -1)
      cout << -1;
    else
      cout << d[0];
    return 0;
  } else {
    if (d[0] <= 0 && d[1] <= 0 && d[2] <= 0) {
      cout << -1;
      return 0;
    }
    for (int i = 0; i < N; ++i) {
      if (d[i] >= 0)
        cout << d[i];
      else
        cout << 0;
    }
  }
  return 0;
}
