#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, x = 1, y = 0, z = 0, ans;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  vector<int> d(3, 10);
  for (int i = 0; i < (M); i++) cin >> s[i] >> c[i];
  if (N == 1) {
    ans == c[0];
  } else if (N == 2) {
    for (int i = 0; i < (M); i++) {
      if (s[i] == 1) {
        y = 10 * c[i];
      } else {
        z = c[i];
      }
    }
    if (y == 0) y = 10;
    ans = y + z;
  } else if (N == 3) {
    for (int i = 0; i < (M); i++) {
      if (s[i] == 1) {
        x = 100 * c[i];
      } else if (s[i] == 2) {
        y = 10 * c[i];
      } else {
        z = c[i];
      }
    }
    ans = x + y + z;
  }
  for (int i = 0; i < (M); i++) {
    if (d[s[i] - 1] == 10) {
      d[s[i] - 1] = c[i];
    } else {
      if (d[s[i] - 1] != c[i]) ans = -1;
      break;
    }
  }
  for (int i = 0; i < (M); i++) {
    if (N == 2) {
      if (s[i] == 1 && c[i] == 0) ans = -1;
    } else if (N == 3) {
      if (s[i] == 1 && c[i] == 0) ans = -1;
    }
  }
  cout << ans << endl;
  return 0;
}
