#include <bits/stdc++.h>
using namespace std;
int N, M;
int s[3];
int c[3];
void input() {
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
}
int main() {
  input();
  int obj[10] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
  bool dup = false;
  int res = 0;
  for (int i = 0; i < M; i++) {
    if (obj[s[i]] != -1 && obj[s[i]] != c[i]) {
      dup = true;
      break;
    } else if (obj[s[i]] == c[i]) {
      continue;
    } else {
      obj[s[i]] = c[i];
      res += pow(10, (N - s[i])) * c[i];
    }
  }
  bool flag = false;
  for (int i = N; i <= 5; i++) {
    if (obj[i] != 0 && obj[i] != -1 || (obj[1] == 0 && N == 1)) {
      flag = true;
    }
  }
  if (dup || !flag) {
    puts("-1");
  } else {
    cout << res << endl;
  }
  return 0;
}
