#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 5;
const int INF = 0x3f3f3f3f;
const int MAXINT = 2147483647;
const int mod = 1000000007;
const long long MAXLONG = 9223372036854775807;
template <class T>
inline bool read(T &ret) {
  char c;
  int sgn;
  if (static_cast<void>(c = getchar()), c == EOF) return 0;
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  sgn = (c == '-') ? -1 : 1;
  ret = (c == '-') ? 0 : (c - '0');
  while (static_cast<void>(c = getchar()), c >= '0' && c <= '9')
    ret = ret * 10 + (c - '0');
  ret *= sgn;
  return 1;
}
template <class T>
inline void write(T x) {
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
int getlen(int x) {
  int ans = 0;
  if (x == 0) ans++;
  while (x) {
    ans++;
    x /= 10;
  }
  return ans;
}
void slove(int question_num) {
  while (question_num--) {
    map<int, int> s;
    int n, m, flag = 1;
    cin >> n >> m;
    for (int i = 1; i <= m; ++i) {
      int a, b;
      cin >> a >> b;
      if (!s.count(a) || (s[a] == 0 && b == 0)) {
        s[a] = b;
      } else
        flag = 0;
    }
    int fin = 1, put = 0;
    for (int i = 0; i < 1000; ++i) {
      int len = getlen(i);
      if (len > n)
        break;
      else if (len < n)
        continue;
      else {
        int a[5] = {0};
        int w = i;
        while (w) {
          a[len--] = w % 10;
          w /= 10;
        }
        for (auto k : s) {
          if (a[k.first] != k.second) {
            fin = 0;
          }
        }
        if (fin && !put) cout << i, put = 1;
        fin = 1;
      }
    }
    if (flag && !put) cout << -1;
  }
}
int main() {
  int num = 1;
  slove(num);
  return 0;
}
