#include <bits/stdc++.h>
using namespace std;
int dig(int a, int b) {
  if (a == 3) {
    return (b);
  }
  if (a == 2) {
    return (b * 10);
  }
  if (a == 1) {
    return (b * 100);
  }
  return 0;
}
int main() {
  int n, m;
  cin >> n >> m;
  int s[m];
  int c[m];
  int ans = 0;
  int g = 0;
  for (int i = 0; i < m; i++) {
    cin >> s[i];
    cin >> c[i];
    if (s[i] == 1) {
      if (ans / 100 != c[i]) {
        if (ans / 100 == 0) {
          ans += dig(s[i], c[i]);
        } else {
          g++;
        }
      }
    }
    if (s[i] == 2) {
      if ((ans / 10) % 10 != c[i]) {
        if (ans / 10 % 10 == 0) {
          ans += dig(s[i], c[i]);
        } else {
          g++;
        }
      }
    }
    if (s[i] == 3) {
      if (ans % 10 != c[i]) {
        if (ans % 10 == 0) {
          ans += dig(s[i], c[i]);
        } else {
          g++;
        }
      }
    }
  }
  if (ans / dig(4 - n, 1) > 0 && ans / dig(4 - n, 1) < 10) {
    if (g < 1) {
      cout << ans << endl;
    } else {
      cout << "-1" << endl;
    }
  } else {
    cout << "-1" << endl;
  }
}
