#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n;
  cin >> m;
  int c[n];
  for (int i = 0; i < n; ++i) {
    c[i] = -1;
  }
  bool norm = true;
  for (int i = 0; i < m; ++i) {
    int s1, c1;
    cin >> s1;
    cin >> c1;
    --s1;
    if (s1 == 0 && c1 == 0) {
      if (n == 1) {
        c[0] = 0;
      } else {
        norm = false;
        break;
      }
    } else if (c[s1] == -1) {
      c[s1] = c1;
    } else if (c[s1] != c1) {
      norm = false;
      break;
    }
  }
  if (norm) {
    int ans = 0;
    for (int i = 0; i < n; ++i) {
      if (c[i] == -1) {
        if (i == 0) {
          ans = 1;
        } else {
          ans *= 10;
        }
      } else {
        ans = ans * 10 + c[i];
      }
    }
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
