#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  bool flag = true;
  int arr[n];
  memset(arr, -1, sizeof arr);
  if (m == 0) {
    if (n == 1) cout << -1 << "\n";
    if (n == 2) cout << 10 << "\n";
    if (n == 3) cout << 100 << "\n";
  } else {
    for (int i = 0; i < m; i++) {
      int si, ci;
      cin >> si >> ci;
      if ((si == 1 && ci == 0) || (arr[si - 1] != -1 && arr[si - 1] != ci)) {
        flag = false;
        break;
      }
      arr[si - 1] = ci;
    }
    if (flag) {
      if (n == 3) {
        if (arr[2] == -1) arr[2] = 0;
        if (arr[1] == -1) arr[1] = 0;
        if (arr[0] == -1) arr[0] = 1;
      } else if (n == 2) {
        if (arr[1] == -1) arr[1] = 0;
        if (arr[0] == -1) arr[0] = 1;
      }
      int answer = 0;
      int y = 1;
      for (int i = n - 1; i >= 0; i--) {
        answer += arr[i] * y;
        y *= 10;
      }
      cout << answer << "\n";
    } else {
      cout << -1 << "\n";
    }
  }
  return 0;
}
