/**
*  _           _                 __                            _   _ _   _                                 _                    _                  _
* | |         | |               / /                           | | (_) | (_)                               | |                  (_)                | |
* | |__   __ _| |_ ___   ___   / /__ ___  _ __ ___  _ __   ___| |_ _| |_ ___   _____ ______ _ __ _   _ ___| |_ ______ ___ _ __  _ _ __  _ __   ___| |_ ___
* | '_ \ / _` | __/ _ \ / _ \ / / __/ _ \| '_ ` _ \| '_ \ / _ \ __| | __| \ \ / / _ \______| '__| | | / __| __|______/ __| '_ \| | '_ \| '_ \ / _ \ __/ __|
* | | | | (_| | || (_) | (_) / / (_| (_) | | | | | | |_) |  __/ |_| | |_| |\ V /  __/      | |  | |_| \__ \ |_       \__ \ | | | | |_) | |_) |  __/ |_\__ \
* |_| |_|\__,_|\__\___/ \___/_/ \___\___/|_| |_| |_| .__/ \___|\__|_|\__|_| \_/ \___|      |_|   \__,_|___/\__|      |___/_| |_|_| .__/| .__/ \___|\__|___/
*                                                  | |                                                                           | |   | |
*                                                  |_|                                                                           |_|   |_|
*
* https://github.com/hatoo/competitive-rust-snippets
*/
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
mod util {
    use std::fmt::Debug;
    use std::io::{stdin, stdout, BufWriter, StdoutLock};
    use std::str::FromStr;
    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }
    #[allow(dead_code)]
    pub fn chars() -> Vec<char> {
        line().chars().collect()
    }
    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
    #[allow(dead_code)]
    pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
        let out = stdout();
        let writer = BufWriter::new(out.lock());
        f(writer)
    }
}
#[allow(unused_macros)]
macro_rules ! get { ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ;; ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; ( $ t : ty ;; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ;; ) ) . collect ::< Vec < _ >> ( ) } ; }
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }
const BIG_STACK_SIZE: bool = true;
#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

#[allow(dead_code)]
fn adjacent4(x: usize, y: usize, sx: usize, sy: usize) -> Box<Iterator<Item = (usize, usize)>> {
    static DXDY: [(isize, isize); 4] = [(-1, 0), (1, 0), (0, -1), (0, 1)];
    Box::new(DXDY.iter().filter_map(move |&(dx, dy)| {
        let nx = x as isize + dx;
        let ny = y as isize + dy;
        if nx >= 0 && nx < sx as isize && ny >= 0 && ny < sy as isize {
            Some((nx as usize, ny as usize))
        } else {
            None
        }
    }))
}

fn solve() {
    loop {
        let (w, h) = get!(i64, i64);
        if w == 0 && h == 0 {
            break;
        }
        let n = get!(usize);
        let abcd = get!(i64, i64, i64, i64; n);

        let mut xx = vec![0, w - 1];
        let mut yy = vec![0, h - 1];

        for &(a, b, c, d) in &abcd {
            xx.push(a);
            xx.push(a + 1);
            xx.push(a - 1);

            xx.push(c);
            xx.push(c + 1);
            xx.push(c - 1);

            yy.push(b);
            yy.push(b + 1);
            yy.push(b - 1);

            yy.push(d);
            yy.push(d + 1);
            yy.push(d - 1);
        }

        xx.retain(|&x| x >= 0 && x < w);
        yy.retain(|&y| y >= 0 && y < h);

        xx.sort();
        xx.dedup();
        yy.sort();
        yy.dedup();

        // debug!(xx);
        // debug!(yy);

        let mut imos = vec![vec![0i32; yy.len() + 1]; xx.len() + 1];

        for (a, b, c, d) in abcd {
            /*
        for i in xx.binary_search(&a).unwrap()..xx.binary_search(&c).unwrap_or(xx.len()) {
            for j in yy.binary_search(&b).unwrap()..yy.binary_search(&d).unwrap_or(yy.len()) {
                map[i][j] = true;
            }
        }
        */
            let x1 = xx.binary_search(&a).unwrap();
            let x2 = xx.binary_search(&c).unwrap_or(xx.len());

            let y1 = yy.binary_search(&b).unwrap();
            let y2 = yy.binary_search(&d).unwrap_or(yy.len());

            imos[x1][y1] += 1;
            imos[x2][y1] -= 1;
            imos[x1][y2] -= 1;
            imos[x2][y2] += 1;
        }

        // debug!(map);
        for i in 0..xx.len() {
            for j in 0..yy.len() {
                imos[i + 1][j] += imos[i][j];
            }
        }
        for i in 0..xx.len() {
            for j in 0..yy.len() {
                imos[i][j + 1] += imos[i][j];
            }
        }

        /*
    for i in 0..xx.len() {
        for j in 0..yy.len() {
            print!("{} ", imos[i][j]);
        }
        println!();
    }
    */
        let mut ans = 0;
        for i in 0..xx.len() {
            for j in 0..yy.len() {
                if imos[i][j] == 0 {
                    ans += 1;
                    let mut stack = vec![(i, j)];
                    while let Some((i, j)) = stack.pop() {
                        if imos[i][j] != 0 {
                            continue;
                        }
                        imos[i][j] = 1;

                        for (a, b) in adjacent4(i, j, xx.len(), yy.len()) {
                            stack.push((a, b));
                        }
                    }
                }
            }
        }

        println!("{}", ans);
    }
}



Measured memory_bytes: 48244