#include <bits/stdc++.h>
using namespace std;
int char_num(char a[], int N) {
  int num = 0;
  int pop = 1;
  for (int i = N; i != 0; --i) {
    num += (a[i - 1] - '0') * pop;
    pop *= 10;
  }
  return num;
}
struct Seiyaku {
  int keta;
  char ch;
};
int main() {
  int N, M;
  cin >> N >> M;
  char num[N];
  Seiyaku syk[M];
  for (int i = 0; i != M; ++i) {
    cin >> syk[i].keta;
    cin >> syk[i].ch;
  }
  int flag = 0;
  int ans = -1;
  if (N == 3) {
    for (char c1 = '1'; c1 <= '9'; ++c1) {
      num[0] = c1;
      for (char c2 = '0'; c2 <= '9'; ++c2) {
        num[1] = c2;
        for (char c3 = '0'; c3 <= '9'; ++c3) {
          num[2] = c3;
          flag = 0;
          for (int j = 0; j != M; ++j) {
            if (num[syk[j].keta - 1] == syk[j].ch) {
              flag += 1;
            }
          }
          if (flag == M) {
            ans = char_num(num, N);
            break;
          }
        }
        if (flag == M) break;
      }
      if (flag == M) break;
    }
  } else if (N == 2) {
    num[0] = '0';
    for (char c2 = '1'; c2 <= '9'; ++c2) {
      num[1] = c2;
      for (char c3 = '0'; c3 <= '9'; ++c3) {
        num[2] = c3;
        flag = 0;
        for (int j = 0; j != M; ++j) {
          if (num[syk[j].keta - 1] == syk[j].ch) {
            flag += 1;
          }
        }
        if (flag == M) {
          ans = char_num(num, N);
          break;
        }
      }
      if (flag == M) break;
    }
  } else if (N == 1) {
    num[0] = '0';
    num[1] = '0';
    for (char c3 = '0'; c3 <= '9'; ++c3) {
      num[2] = c3;
      flag = 0;
      for (int j = 0; j != M; ++j) {
        if (num[syk[j].keta - 1] == syk[j].ch) {
          flag += 1;
        }
      }
      if (flag == M) {
        ans = char_num(num, N);
        break;
      }
    }
  }
  cout << ans << endl;
}
