#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  int s[3];
  cin >> n >> m;
  int t1, t2;
  s[0] = -1;
  s[1] = -1;
  s[2] = -1;
  bool flag = 0;
  for (int i = 0; i < m; i++) {
    cin >> t1 >> t2;
    if (s[t1 - 1] == -1)
      s[t1 - 1] = t2;
    else if (s[t1 - 1] != t2)
      flag = 1;
  }
  if (n == 1) {
    if (s[1] != -1 || s[2] != -1) flag = 1;
    if (flag) {
      cout << -1 << endl;
      return 0;
    }
    if (s[0] == -1) s[0] = 0;
    cout << s[0] << endl;
    return 0;
  }
  if (n == 2) {
    if (s[2] != -1 || s[0] == 0) flag = 1;
    if (s[0] == -1) s[0] = 1;
    if (s[1] == -1) s[1] = 0;
    if (flag) {
      cout << -1 << endl;
      return 0;
    }
    cout << s[0] * 10 + s[1] << endl;
    return 0;
  }
  if (n == 3) {
    if (s[0] != 0) {
      if (s[0] == -1) s[0] = 1;
      if (s[1] == -1) s[1] = 0;
      if (s[2] == -1) s[2] = 0;
      cout << s[0] * 100 + s[1] * 10 + s[2] << endl;
      return 0;
    }
    cout << -1 << endl;
  }
  return 0;
}
